ShowPic22.cpp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698
  1. // ShowPic22.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "ShowPic22.h"
  6. #include "MyLock.h"
  7. #include "ShowEffect.h"
  8. #include "CutPhoto.h"
  9. #include "ChoosePhotoBase.h"
  10. #define PCL_R(p) (((RGBQUAD*)(p))->rgbRed)
  11. #define PCL_G(p) (((RGBQUAD*)(p))->rgbGreen)
  12. #define PCL_B(p) (((RGBQUAD*)(p))->rgbBlue)
  13. #define PCL_A(p) (((RGBQUAD*)(p))->rgbReserved)
  14. /////////////////////////////////////////////////////////////////////////////
  15. HANDLE Lock(char* name)
  16. {
  17. try
  18. {
  19. HANDLE mutex;
  20. // Try to open an exist mutex firstly.
  21. mutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, name);
  22. if (NULL == mutex) // If the mutex does not exist, create it with the certain name.
  23. {
  24. mutex = CreateMutex(NULL, TRUE, name);
  25. }
  26. else // If the mutex already exist, wait for other thread release it.
  27. {
  28. WaitForSingleObject(mutex, INFINITE);
  29. }
  30. return mutex;
  31. }
  32. catch (...)
  33. {
  34. }
  35. }
  36. bool Unlock(HANDLE mutex)
  37. {
  38. try
  39. {
  40. if (0 == ReleaseMutex(mutex)) // Failed to release mutex
  41. {
  42. return false;
  43. }
  44. else // Successed in release mutex
  45. {
  46. CloseHandle(mutex);
  47. mutex = NULL;
  48. return true;
  49. }
  50. }
  51. catch (...)
  52. {
  53. }
  54. }
  55. ShowPic22::ShowPic22(CWnd* pParent) : CDialog(ShowPic22::IDD, pParent)
  56. {
  57. m_pCurShowImg = NULL;
  58. m_pCurShowSmallImg = NULL;
  59. m_pImagetemp = NULL;
  60. m_pbmp = NULL;
  61. m_pParent = NULL;
  62. m_bauto = 0;
  63. m_fscale = 1;
  64. m_bScroll = 0;
  65. m_bTerminate = false;
  66. m_bRunning = false;
  67. m_hThread = NULL;
  68. m_bProcessing = 0;
  69. m_bInit = 0;
  70. m_bShowImgInfo = 0;
  71. m_bShowEffect = 0;
  72. m_AryOfImgPath = NULL;
  73. m_pPathArrayBigsize = NULL;
  74. m_bChooseBig = 0;
  75. }
  76. void ShowPic22::DoDataExchange(CDataExchange* pDX)
  77. {
  78. CDialog::DoDataExchange(pDX);
  79. DDX_Control(pDX, IDC_STATIC1, m_sta1);
  80. }
  81. BEGIN_MESSAGE_MAP(ShowPic22, CDialog)
  82. ON_WM_PAINT()
  83. ON_WM_DESTROY()
  84. ON_WM_LBUTTONDOWN()
  85. ON_WM_LBUTTONUP()
  86. ON_WM_MOUSEWHEEL()
  87. ON_WM_ERASEBKGND()
  88. ON_WM_RBUTTONDOWN()
  89. ON_WM_TIMER()
  90. ON_WM_CLOSE()
  91. ON_WM_MOUSEMOVE()
  92. ON_WM_CTLCOLOR()
  93. ON_MESSAGE(WM_USER + 200, ShowInfo2)
  94. END_MESSAGE_MAP()
  95. /////////////////////////////////////////////////////////////////////////////
  96. BOOL ShowPic22::OnEraseBkgnd(CDC* pDC)
  97. {
  98. return 1;
  99. }
  100. unsigned __stdcall GenThumbImgThread(LPVOID lpParam)
  101. {
  102. try
  103. {
  104. ShowPic22 *pThis = (ShowPic22*)lpParam;
  105. int posbak = pThis->m_nCurImgPos; // m_pos 选片时选中的相片列编号,即要查看的相片;
  106. // 以下4个变量用途何为?
  107. int pos(0);
  108. BOOL bNext = 1; // 图片位置与posbak一致时保持不变;
  109. BOOL bFirst = 1; // 记录第一次运行的什么情况?
  110. int count(0); // 用于记录什么的数量?
  111. while (1)
  112. {
  113. // 对话框销毁,线程退出;
  114. if (pThis->m_bTerminate)
  115. break;
  116. // 播放幻灯或未初始化时,线程进入睡眠,让出CPU周期;
  117. if (pThis->m_bauto || (pThis->m_bInit == 0 && bFirst == 0))
  118. {
  119. ::Sleep(1000);
  120. continue;
  121. }
  122. if (bFirst)
  123. count = 2;
  124. else
  125. count = 5;
  126. bFirst = 0;
  127. for (int i = 0; i < count; i++)
  128. {
  129. if (pThis->m_bTerminate)break;
  130. if (pThis->m_bauto)break;
  131. if (posbak != pThis->m_nCurImgPos)
  132. {
  133. if (pThis->m_nCurImgPos > posbak)
  134. bNext = 1;
  135. else
  136. bNext = 0;
  137. posbak = pThis->m_nCurImgPos;
  138. i = 0;
  139. continue;
  140. }
  141. if (bNext)
  142. {
  143. switch (i)
  144. {
  145. case 0:
  146. pos = posbak;
  147. break;
  148. case 1:
  149. pos = posbak + 1;
  150. break;
  151. case 2:
  152. pos = posbak + 2;
  153. break;
  154. case 3:
  155. pos = posbak - 1;
  156. break;
  157. case 4:
  158. pos = posbak + 3;
  159. break;
  160. }
  161. }
  162. else
  163. {
  164. switch (i)
  165. {
  166. case 0:
  167. pos = posbak;
  168. break;
  169. case 1:
  170. pos = posbak - 1;
  171. break;
  172. case 2:
  173. pos = posbak - 2;
  174. break;
  175. case 3:
  176. pos = posbak + 1;
  177. break;
  178. case 4:
  179. pos = posbak - 3;
  180. break;
  181. }
  182. }
  183. HANDLE handle = Lock("shgenimagethread");
  184. while (pos >= pThis->m_AryOfImgPath->GetSize())
  185. pos -= pThis->m_AryOfImgPath->GetSize();
  186. while (pos < 0)
  187. pos += pThis->m_AryOfImgPath->GetSize();
  188. // 判断指定索引的相片路径是否被加载;
  189. BOOL bFind = 0;
  190. for (int n = 0; n < pThis->m_nPosArray.GetSize(); n++)
  191. {
  192. if (pos == pThis->m_nPosArray.ElementAt(n)){
  193. bFind = 1;
  194. break;
  195. }// if;
  196. }// for;
  197. if (bFind){
  198. Unlock(handle);
  199. continue;
  200. }// if;
  201. // 获取相片路径;
  202. CString path = pThis->m_AryOfImgPath->ElementAt(pos);
  203. if (pThis->m_bChooseBig && pThis->m_nCurImgPos == pos)
  204. {
  205. path = pThis->m_pPathArrayBigsize->ElementAt(pos);
  206. pThis->m_bChooseBig = 0;
  207. }
  208. // img为"m"图或大图,加载指定名称的图片;
  209. Image *img = NULL;
  210. Image *imgsmall = NULL;
  211. ::LoadImageFromBuf(&img, path);
  212. if (img == NULL)
  213. {// 如果加载相片失败,则使用空白图片代替;
  214. Bitmap *pNULLBmp = new Bitmap(100, 100, PixelFormat24bppRGB);
  215. Graphics graph2(pNULLBmp);
  216. graph2.Clear(Color(255, 0, 0, 0));
  217. Bitmap *pNULLBmp2 = new Bitmap(100, 100, PixelFormat24bppRGB);
  218. Graphics graph3(pNULLBmp2);
  219. graph3.Clear(Color(255, 0, 0, 0));
  220. pThis->m_AryOfImgPtr.Add(pNULLBmp);
  221. pThis->m_AryOfSmallImgPtr.Add(pNULLBmp2);
  222. pThis->m_nPosArray.Add(pos);
  223. Unlock(handle);
  224. continue;
  225. }
  226. if (img->GetWidth() == 0)
  227. {// 如果加载相片失败,则使用空白图片代替;
  228. Bitmap *pNULLBmp = new Bitmap(100, 100, PixelFormat24bppRGB);
  229. Graphics graph2(pNULLBmp);
  230. graph2.Clear(Color(255, 0, 0, 0));
  231. Bitmap *pNULLBmp2 = new Bitmap(100, 100, PixelFormat24bppRGB);
  232. Graphics graph3(pNULLBmp2);
  233. graph3.Clear(Color(255, 0, 0, 0));
  234. pThis->m_AryOfImgPtr.Add(pNULLBmp);
  235. pThis->m_AryOfSmallImgPtr.Add(pNULLBmp2);
  236. pThis->m_nPosArray.Add(pos);
  237. Unlock(handle);
  238. continue;
  239. }
  240. CRect rc;
  241. pThis->InitRc(img, rc); //
  242. //GetThumbnailImage进行图片缩放操作
  243. imgsmall = img->GetThumbnailImage(rc.Width(), rc.Height(), NULL, NULL);
  244. Graphics graphic(imgsmall);//防止GetThumbnailImage影响质量
  245. graphic.DrawImage(img, 0, 0, imgsmall->GetWidth(), imgsmall->GetHeight());
  246. int orientation = GetOrientation(img);
  247. if (orientation == 8)
  248. {
  249. imgsmall->RotateFlip(Rotate270FlipNone);
  250. img->RotateFlip(Rotate270FlipNone);
  251. }
  252. else if (orientation == 6)
  253. {
  254. imgsmall->RotateFlip(Rotate90FlipNone);
  255. img->RotateFlip(Rotate90FlipNone);
  256. }
  257. pThis->m_AryOfImgPtr.Add(img);
  258. pThis->m_AryOfSmallImgPtr.Add(imgsmall);
  259. pThis->m_nPosArray.Add(pos);
  260. //10张图片缓存
  261. if (pThis->m_AryOfImgPtr.GetSize() > 10)
  262. {// 如果加载的图片超过10过,删除最早加载的第一张;
  263. if (pThis->m_pCurShowImg != pThis->m_AryOfImgPtr.ElementAt(0))
  264. {// 如果第一张不是当前显示的图片,从内存中删除掉;
  265. delete pThis->m_AryOfImgPtr.ElementAt(0);
  266. delete pThis->m_AryOfSmallImgPtr.ElementAt(0);
  267. pThis->m_AryOfImgPtr.RemoveAt(0);
  268. pThis->m_AryOfSmallImgPtr.RemoveAt(0);
  269. pThis->m_nPosArray.RemoveAt(0);
  270. }
  271. }
  272. Unlock(handle);
  273. }
  274. ::Sleep(200);
  275. }
  276. pThis->m_bRunning = false;
  277. pThis->m_bTerminate = false;
  278. _endthreadex(0);
  279. }
  280. catch (...)
  281. {
  282. }
  283. return 0;
  284. }
  285. BOOL ShowPic22::OnInitDialog() // 初始化;
  286. {
  287. CDialog::OnInitDialog();
  288. m_bShowImgInfo = 1;
  289. try
  290. {
  291. g_nSendCode = 0;
  292. RunPicThread();
  293. if (m_bShowImgInfo)
  294. GetDlgItem(IDC_STATIC2)->ShowWindow(SW_SHOW);
  295. m_rcScreen = CRect(0, 0, g_screenwid, g_screenhei);
  296. ::SetWindowPos(m_hWnd, HWND_TOP, 0, 0, g_screenwid, g_screenhei, SWP_SHOWWINDOW);
  297. // m_pbmp=new Bitmap(g_screenwid, g_screenhei, PixelFormat24bppRGB );
  298. m_pbmp = new Bitmap(g_screenwid, g_screenhei, PixelFormat32bppARGB);
  299. // LoadImage();
  300. if (m_pParent)
  301. m_pParent->m_showpichwd = m_hWnd;
  302. m_dlg.Create(IDD_DLGAnimateWindow, this);
  303. m_dlg.m_pParent = this;
  304. m_dlg.m_pbmp = m_pbmp;
  305. m_dlg.m_pRc = &m_rcImgShow;
  306. m_dlg.MoveWindow(m_rcScreen);
  307. if (m_PicBar.GetSafeHwnd() == NULL)
  308. {
  309. if (m_pParent == NULL)
  310. m_PicBar.m_bShowCut = 0;
  311. else if (m_pParent->m_Runingmode)
  312. m_PicBar.m_bShowCut = 0;
  313. m_PicBar.PreLoad();
  314. m_PicBar.SetLiaPath("4.lia");
  315. m_PicBar.Create(IDD_DLGmydlg, this);
  316. }
  317. if (m_PreviewDlg.GetSafeHwnd() == NULL)
  318. {
  319. m_PreviewDlg.Create(IDD_DIALOG30, this);
  320. CRect rc;
  321. rc.top = 50;
  322. rc.bottom = g_screenhei - 50;
  323. rc.right = g_screenwid - 10;
  324. rc.left = rc.right - 100;
  325. ///////////////////////////
  326. rc.left = g_screenwid - 20;
  327. rc.right = rc.left + 100;
  328. ///////////////////////////
  329. m_PreviewDlg.MoveWindow(rc);
  330. m_PreviewDlg.m_pPathArray = m_AryOfImgPath;
  331. m_PreviewDlg.InitCtrl();
  332. }
  333. // m_PicBar.SetParent (this);
  334. if (m_PicBar.m_bInit)
  335. {
  336. m_PicBar.m_pParent = this;
  337. int hei;
  338. m_PicBar.GetWindowRect(m_picbarrc);
  339. hei = m_picbarrc.Height();
  340. m_picbarrc.bottom = g_screenhei - 10;
  341. m_picbarrc.top = m_picbarrc.bottom - hei;
  342. m_PicBar.MoveWindow(m_picbarrc);
  343. m_startpt2.x = m_startpt2.y = 0;
  344. }
  345. m_sta1.SetFocus();
  346. LoadImage();
  347. m_PreviewDlg.ShowWindow(SW_SHOW);
  348. }
  349. catch (...)
  350. {
  351. }
  352. return TRUE;
  353. }
  354. inline void RGBtoHLS(int R, int G, int B, double* H, double* L, double* S)
  355. {
  356. const int n_cmax = max(B, max(R, G)),
  357. n_cmin = min(B, min(R, G));
  358. *L = (n_cmax + n_cmin) / 2.0 / 255.0;
  359. if (n_cmax == n_cmin)
  360. {
  361. *S = *H = 0.0;
  362. return;
  363. }
  364. const double r = (double)R / 255.0,
  365. g = (double)G / 255.0,
  366. b = (double)B / 255.0,
  367. cmax = n_cmax / 255.0,
  368. cmin = n_cmin / 255.0,
  369. delta = cmax - cmin;
  370. if (*L < 0.5)
  371. *S = delta / (cmax + cmin);
  372. else
  373. *S = delta / (2.0 - cmax - cmin);
  374. if (R == n_cmax)
  375. *H = (g - b) / delta;
  376. else if (G == n_cmax)
  377. *H = 2.0 + (b - r) / delta;
  378. else
  379. *H = 4.0 + (r - g) / delta;
  380. *H /= 6.0;
  381. if (*H < 0.0)
  382. *H += 1.0;
  383. }
  384. RGBQUAD __DoubleRGB_to_RGB(const double& r, const double& g, const double& b)
  385. {
  386. RGBQUAD rgb;
  387. rgb.rgbRed = max(0, min(255, (int)r * 255));
  388. rgb.rgbGreen = max(0, min(255, (int)g * 255));
  389. rgb.rgbBlue = max(0, min(255, (int)b * 255));
  390. return rgb;
  391. }
  392. inline double __HLS_Value(const double& m1, const double& m2, double h)
  393. {
  394. if (h > 6.0)
  395. h -= 6.0;
  396. else if (h < 0.0)
  397. h += 6.0;
  398. if (h < 1.0)
  399. return m1 + (m2 - m1) * h;
  400. else if (h < 3.0)
  401. return m2;
  402. else if (h < 4.0)
  403. return m1 + (m2 - m1) * (4.0 - h);
  404. return m1;
  405. }
  406. inline RGBQUAD HLStoRGB(const double& H, const double& L, const double& S)
  407. {
  408. double m1, m2;
  409. if (L < 0.5)
  410. m2 = L * (1.0 + S);
  411. else
  412. m2 = L + S - L*S;
  413. m1 = 2.0*L - m2;
  414. return __DoubleRGB_to_RGB(__HLS_Value(m1, m2, H*6.0 + 2.0),
  415. __HLS_Value(m1, m2, H*6.0),
  416. __HLS_Value(m1, m2, H*6.0 - 2.0));
  417. }
  418. void Autocontrast(Bitmap *pBmpImage)
  419. {
  420. return;
  421. try
  422. {
  423. if (pBmpImage == NULL)return;
  424. BitmapData bitmapData;
  425. UINT* pixels;
  426. Rect rc(0, 0, pBmpImage->GetWidth(), pBmpImage->GetHeight());
  427. pBmpImage->LockBits(
  428. rc,
  429. ImageLockModeWrite,
  430. PixelFormat32bppARGB,
  431. &bitmapData);
  432. // Write to the temporary buffer provided by LockBits. RGB
  433. pixels = (UINT*)bitmapData.Scan0;
  434. DWORD wids = bitmapData.Stride / 4;
  435. Color color;
  436. BYTE R, G, B;
  437. double H, L, S;
  438. int iPercent = 128 * 110 / 100; // 转换成x/128;
  439. int iPercentSat = 128 * 120 / 100; // 转换成x/128;
  440. RGBQUAD rgb2; RGBTRIPLE rgb;
  441. for (INT row = 0; row < rc.Height; ++row)
  442. {
  443. for (INT col = 0; col < rc.Width; ++col)
  444. {
  445. color.SetValue(pixels[row * wids + col]);
  446. R = min(255, max(0, 128 + (color.GetR() - 128) * iPercent / 128));
  447. G = min(255, max(0, 128 + (color.GetG() - 128) * iPercent / 128));
  448. B = min(255, max(0, 128 + (color.GetB() - 128) * iPercent / 128));
  449. rgb.rgbtRed = color.GetR();
  450. rgb.rgbtGreen = color.GetG();
  451. rgb.rgbtBlue = color.GetB();
  452. FCColor::RGBtoHLS(&rgb, &H, &L, &S);
  453. S = S * iPercentSat / 128;
  454. rgb2 = FCColor::HLStoRGB(H, L, S);
  455. pixels[row * wids + col] = Color::MakeARGB(255, rgb2.rgbRed, rgb2.rgbGreen, rgb2.rgbBlue);
  456. // pixels[row * wids + col]=Color::MakeARGB(255, R, G, B );
  457. }
  458. }
  459. pBmpImage->UnlockBits(&bitmapData);
  460. }
  461. catch (...)
  462. {
  463. }
  464. }
  465. void Autosaturation(Bitmap *pBmpImage)
  466. {
  467. #ifdef HIGH_VERSION
  468. try
  469. {
  470. if(pBmpImage==NULL)return;
  471. if(g_pMainWnd->m_pToneColorDlg2->m_saturation==100)return;
  472. BitmapData bitmapData;
  473. UINT* pixels;
  474. Rect rc(0, 0, pBmpImage->GetWidth(), pBmpImage->GetHeight() );
  475. pBmpImage->LockBits(
  476. rc,
  477. ImageLockModeWrite,
  478. PixelFormat32bppARGB ,
  479. &bitmapData);
  480. // Write to the temporary buffer provided by LockBits. RGB
  481. pixels = (UINT*)bitmapData.Scan0;
  482. DWORD wids=bitmapData.Stride/4;
  483. Color color;
  484. double H, L, S ;
  485. RGBTRIPLE rgb;
  486. RGBQUAD rgb2;
  487. int iPercentSat = 128 * g_pMainWnd->m_pToneColorDlg2->m_saturation / 100 ; // 转换成x/128
  488. for(INT row = 0; row < rc.Height; ++row)
  489. {
  490. for(INT col = 0; col < rc.Width; ++col)
  491. {
  492. color.SetValue(pixels[row * wids + col]);
  493. rgb.rgbtRed =color.GetR();
  494. rgb.rgbtGreen =color.GetG();
  495. rgb.rgbtBlue =color.GetB();
  496. FCColor::RGBtoHLS (&rgb, &H, &L, &S) ;
  497. S = S * iPercentSat / 128 ;
  498. rgb2 = FCColor::HLStoRGB (H, L, S) ;
  499. pixels[row * wids + col]=Color::MakeARGB(color.GetA(), rgb2.rgbRed, rgb2.rgbGreen, rgb2.rgbBlue );
  500. }
  501. }
  502. pBmpImage->UnlockBits(&bitmapData);
  503. }
  504. catch(...)
  505. {
  506. }
  507. #endif
  508. }
  509. void ShowPic22::OnPaint()
  510. {
  511. CPaintDC dc(this);
  512. try
  513. {
  514. CRect rc;
  515. GetClientRect(rc);
  516. if (m_pCurShowImg && m_bauto == 0)
  517. {// m_bauto 自动播放; m_pCurShowImg当前需要显示的相片指针;
  518. Graphics graph(m_pbmp);
  519. graph.Clear(Color(255, 0, 0, 0));
  520. Image *img;
  521. if (m_pImagetemp && m_bScroll == 0)
  522. img = m_pImagetemp;
  523. else
  524. img = m_pCurShowSmallImg;
  525. m_bScroll = 0;
  526. int width, height;
  527. width = img->GetWidth();
  528. height = img->GetHeight();
  529. ///////////////
  530. Rect destinationRect(m_rcImgShow.left, m_rcImgShow.top, m_rcImgShow.Width(), m_rcImgShow.Height());
  531. // graph.SetInterpolationMode(InterpolationModeHighQualityBicubic);
  532. graph.DrawImage(img, destinationRect, 0, 0, width, height, UnitPixel);
  533. Graphics graph2(dc.GetSafeHdc());
  534. Autocontrast(m_pbmp);
  535. graph2.DrawImage(m_pbmp, 0, 0);
  536. }
  537. else
  538. {
  539. // dc.FillSolidRect (rc, 0);
  540. }
  541. }
  542. catch (...)
  543. {
  544. }
  545. }
  546. void ShowPic22::OnDestroy()
  547. {
  548. try
  549. {
  550. g_nSendCode = 0;
  551. for (int n = 0; n < m_nPosArray.GetSize(); n++)
  552. {
  553. m_pCurShowImg = m_AryOfImgPtr.ElementAt(n);
  554. m_pCurShowSmallImg = m_AryOfSmallImgPtr.ElementAt(n);
  555. delete m_pCurShowImg;
  556. delete m_pCurShowSmallImg;
  557. }
  558. DELETEP(m_pImagetemp)
  559. DELETEP(m_pbmp)
  560. KillTimer(1);
  561. }
  562. catch (...)
  563. {
  564. }
  565. CDialog::OnDestroy();
  566. }
  567. void ShowPic22::LoadImage()
  568. {
  569. try
  570. {
  571. ::SetForegroundWindow(m_hWnd);
  572. KillTimer(5);
  573. if (m_AryOfImgPath->GetSize() == 0)
  574. return;
  575. m_pCurShowImg = m_pCurShowSmallImg = NULL;
  576. for (int n = 0; n < m_nPosArray.GetSize(); n++){
  577. if (m_nCurImgPos == m_nPosArray.ElementAt(n)){
  578. m_pCurShowImg = m_AryOfImgPtr.ElementAt(n);
  579. m_pCurShowSmallImg = m_AryOfSmallImgPtr.ElementAt(n);
  580. break;
  581. }//if;
  582. }//for;
  583. if (m_pCurShowImg == NULL && (m_bauto || m_bInit == 0))
  584. {
  585. HANDLE handle = Lock("shgenimagethread");
  586. CString path = m_AryOfImgPath->ElementAt(m_nCurImgPos);
  587. if (m_bChooseBig && m_pPathArrayBigsize && m_pPathArrayBigsize->GetSize() > m_nCurImgPos)
  588. {// 如果使用的是原图模式,加载原图;
  589. path = m_pPathArrayBigsize->ElementAt(m_nCurImgPos);
  590. }
  591. // 从文件中加载图片;
  592. LoadImageFromBuf(&m_pCurShowImg, path);
  593. if (m_pCurShowImg == NULL)
  594. {//如果加载相片失败,使用空白图片代替;
  595. Bitmap *pNULLBmp = new Bitmap(100, 100, PixelFormat24bppRGB);
  596. Graphics graph2(pNULLBmp);
  597. graph2.Clear(Color(255, 0, 0, 0));
  598. m_pCurShowImg = pNULLBmp;
  599. }
  600. if (m_pCurShowImg->GetWidth() == 0)
  601. {
  602. m_bChooseBig = 0;
  603. Unlock(handle);
  604. return;
  605. }
  606. InitRc();
  607. m_pCurShowSmallImg = m_pCurShowImg->GetThumbnailImage(m_rcImgShow.Width(), m_rcImgShow.Height(), NULL, NULL);
  608. Graphics graphic(m_pCurShowSmallImg);//防止GetThumbnailImage影响质量
  609. graphic.DrawImage(m_pCurShowImg, 0, 0, m_pCurShowSmallImg->GetWidth(), m_pCurShowSmallImg->GetHeight());
  610. int orientation = GetOrientation(m_pCurShowImg);
  611. if (orientation == 8)
  612. {
  613. m_pCurShowImg->RotateFlip(Rotate270FlipNone);
  614. m_pCurShowSmallImg->RotateFlip(Rotate270FlipNone);
  615. }
  616. else if (orientation == 6)
  617. {
  618. m_pCurShowImg->RotateFlip(Rotate90FlipNone);
  619. m_pCurShowSmallImg->RotateFlip(Rotate90FlipNone);
  620. }
  621. // 存入到数组中;
  622. m_AryOfImgPtr.Add(m_pCurShowImg);
  623. m_AryOfSmallImgPtr.Add(m_pCurShowSmallImg);
  624. m_nPosArray.Add(m_nCurImgPos);
  625. if (m_AryOfImgPtr.GetSize() > 10)
  626. {// 如果加载的图片超过10张,删除第一张;
  627. if (m_pCurShowImg != m_AryOfImgPtr.ElementAt(0))
  628. {
  629. delete m_AryOfImgPtr.ElementAt(0);
  630. delete m_AryOfSmallImgPtr.ElementAt(0);
  631. m_AryOfImgPtr.RemoveAt(0);
  632. m_AryOfSmallImgPtr.RemoveAt(0);
  633. m_nPosArray.RemoveAt(0);
  634. }
  635. }
  636. m_bChooseBig = 0;
  637. Unlock(handle);
  638. }
  639. else if (m_pCurShowImg == NULL)
  640. {
  641. SetTimer(5, 1, NULL);
  642. return;
  643. }
  644. if (m_pImagetemp)
  645. delete m_pImagetemp;
  646. m_pImagetemp = NULL;
  647. InitRc();
  648. if (m_bauto)
  649. {// 自动播放相片;
  650. if (m_dlg.m_effect == 1 || m_dlg.m_effect == 2)
  651. {
  652. CDC *pDC = GetDC();
  653. HDC hdc = ::GetDC(NULL);
  654. ::BitBlt(pDC->GetSafeHdc(), 0, 0, g_screenwid, g_screenhei, hdc, 0, 0, SRCCOPY);
  655. ReleaseDC(pDC);
  656. }
  657. m_dlg.m_time = m_PicBar.m_time * 1000;
  658. m_dlg.SetImage(m_pCurShowSmallImg);
  659. if (m_dlg.m_effect == 1 || m_dlg.m_effect == 2)
  660. {
  661. m_dlg.ShowWindow(SW_HIDE);
  662. }
  663. // ShowAlpha里有SetTimer(1);
  664. m_dlg.ShowAlpha();
  665. }
  666. else
  667. {
  668. ShowInfo();
  669. Invalidate();
  670. }
  671. }
  672. catch (...)
  673. {
  674. }
  675. }
  676. void ShowPic22::OnLButtonDown(UINT nFlags, CPoint point)
  677. {
  678. SetCapture(); // 设置窗口捕获鼠标;
  679. m_startpt = m_startpt3 = point;
  680. CDialog::OnLButtonDown(nFlags, point);
  681. }
  682. void ShowPic22::OnMouseMove(UINT nFlags, CPoint point)
  683. {
  684. if (GetCapture() != this)
  685. return;
  686. if (m_rcImgShow.Width() > m_rcScreen.Width())
  687. {
  688. if (m_rcImgShow.left <m_rcScreen.left && point.x>m_startpt.x)
  689. {
  690. int dt = min(point.x - m_startpt.x, m_rcScreen.left - m_rcImgShow.left);
  691. m_rcImgShow.left += dt;
  692. m_rcImgShow.right += dt;
  693. }
  694. else if (m_rcImgShow.right > m_rcScreen.right && point.x < m_startpt.x)
  695. {
  696. int dt = min(m_startpt.x - point.x, m_rcImgShow.right - m_rcScreen.right);
  697. m_rcImgShow.left -= dt;
  698. m_rcImgShow.right -= dt;
  699. }m_startpt3 = point;
  700. }
  701. if (m_rcImgShow.Height() > m_rcScreen.Height())
  702. {
  703. if (m_rcImgShow.top <m_rcScreen.top && point.y>m_startpt.y)
  704. {
  705. int dt = min(point.y - m_startpt.y, m_rcScreen.top - m_rcImgShow.top);
  706. m_rcImgShow.top += dt;
  707. m_rcImgShow.bottom += dt;
  708. }
  709. else if (m_rcImgShow.bottom > m_rcScreen.bottom && point.y < m_startpt.y)
  710. {
  711. int dt = min(m_startpt.y - point.y, m_rcImgShow.bottom - m_rcScreen.bottom);
  712. m_rcImgShow.top -= dt;
  713. m_rcImgShow.bottom -= dt;
  714. }m_startpt3 = point;
  715. }
  716. m_startpt = point;
  717. Invalidate();
  718. CDialog::OnMouseMove(nFlags, point);
  719. }
  720. void ShowPic22::OnLButtonUp(UINT nFlags, CPoint point)
  721. {
  722. if (GetCapture() != this)return;
  723. ReleaseCapture();
  724. if (point.x - m_startpt3.x > 30)
  725. Next();
  726. else if (m_startpt3.x - point.x > 30)
  727. Pre();
  728. CDialog::OnLButtonUp(nFlags, point);
  729. }
  730. BOOL ShowPic22::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
  731. {
  732. if (m_pCurShowImg == NULL)
  733. return 1;
  734. if (m_bauto)
  735. return 1;
  736. if (m_bProcessing)
  737. return 1;
  738. m_bScroll = 1;
  739. if (zDelta > 0)
  740. {//放大图片;
  741. // if(m_fscale>4)return 1;
  742. m_fscale *= 1.2;
  743. int dtx = (m_fscale*m_rcImgShowBack.Width() - m_rcImgShow.Width()) / 2.0;
  744. int dty = (m_fscale*m_rcImgShowBack.Height() - m_rcImgShow.Height()) / 2.0;
  745. m_rcImgShow.left -= dtx;
  746. m_rcImgShow.right += dtx;
  747. m_rcImgShow.top -= dty;
  748. m_rcImgShow.bottom += dty;
  749. Invalidate();
  750. }
  751. else
  752. {// 缩小图片;
  753. if (m_fscale <= 1)
  754. return 1;
  755. m_fscale /= 1.2;
  756. if (m_fscale < 1)
  757. m_fscale = 1;
  758. int dtx = (m_fscale*m_rcImgShowBack.Width() - m_rcImgShow.Width()) / 2.0;
  759. int dty = (m_fscale*m_rcImgShowBack.Height() - m_rcImgShow.Height()) / 2.0;
  760. m_rcImgShow.left -= dtx;
  761. m_rcImgShow.right += dtx;
  762. m_rcImgShow.top -= dty;
  763. m_rcImgShow.bottom += dty;
  764. if (m_rcImgShowBack.Height() == m_rcScreen.Height())
  765. {
  766. if (m_rcImgShow.top < m_rcScreen.top && m_rcImgShow.bottom < m_rcScreen.bottom)
  767. {
  768. dtx = m_rcScreen.bottom - m_rcImgShow.bottom;
  769. m_rcImgShow.top += dtx;
  770. m_rcImgShow.bottom += dtx;
  771. }
  772. else if (m_rcImgShow.top >m_rcScreen.top && m_rcImgShow.bottom > m_rcScreen.bottom)
  773. {
  774. dtx = m_rcImgShow.top - m_rcScreen.top;
  775. m_rcImgShow.top -= dtx;
  776. m_rcImgShow.bottom -= dtx;
  777. }
  778. dtx = m_rcImgShow.Width();
  779. m_rcImgShow.left = (m_rcScreen.Width() - dtx) / 2;
  780. m_rcImgShow.right = m_rcImgShow.left + dtx;
  781. }
  782. if (m_rcImgShowBack.Width() == m_rcScreen.Width())
  783. {
  784. if (m_rcImgShow.left < m_rcScreen.left && m_rcImgShow.right < m_rcScreen.right)
  785. {
  786. dtx = m_rcScreen.right - m_rcImgShow.right;
  787. m_rcImgShow.left += dtx;
  788. m_rcImgShow.right += dtx;
  789. }
  790. else if (m_rcImgShow.left >m_rcScreen.left && m_rcImgShow.right > m_rcScreen.right)
  791. {
  792. dtx = m_rcImgShow.left - m_rcScreen.left;
  793. m_rcImgShow.left -= dtx;
  794. m_rcImgShow.right -= dtx;
  795. }
  796. dtx = m_rcImgShow.Height();
  797. m_rcImgShow.top = (m_rcScreen.Height() - dtx) / 2;
  798. m_rcImgShow.bottom = m_rcImgShow.top + dtx;
  799. }
  800. Invalidate();
  801. /* int dtx=(m_fscale-1)*m_rcImgShowBack.Width ()/2.0;
  802. int dty=(m_fscale-1)*m_rcImgShowBack.Height ()/2.0;
  803. m_rcImgShow=m_rcImgShowBack;
  804. m_rcImgShow.left -=dtx;
  805. m_rcImgShow.right +=dtx;
  806. m_rcImgShow.top -=dty;
  807. m_rcImgShow.bottom +=dty;
  808. Invalidate();*/
  809. }
  810. KillTimer(2);
  811. SetTimer(2, 100, NULL);
  812. return CDialog::OnMouseWheel(nFlags, zDelta, pt);
  813. }
  814. BOOL ShowPic22::PreTranslateMessage(MSG* pMsg) // 键盘和按钮响应事件;
  815. {
  816. if (pMsg->message == WM_MOUSEMOVE)
  817. {
  818. if (m_bShowEffect)return 1;
  819. if (m_PicBar.m_bInit && m_pCurShowImg)
  820. {
  821. CPoint point;
  822. ::GetCursorPos(&point);
  823. if (abs(m_startpt2.x - point.x) > 5 || abs(m_startpt2.y - point.y) > 5)
  824. {
  825. m_startpt2 = point;
  826. m_PicBar.ShowWindow(SW_SHOW);
  827. SetTimer(3, 1500, NULL);
  828. }
  829. }
  830. }
  831. else if (pMsg->message == WM_KEYDOWN)
  832. {
  833. if (m_bShowEffect)return 1;
  834. switch (pMsg->wParam)
  835. {
  836. case VK_RETURN:
  837. return 1;
  838. case VK_ESCAPE:
  839. KillTimer(6);
  840. SetTimer(6, 100, NULL);
  841. return 1;
  842. case VK_F2:
  843. return 1;
  844. if (m_pParent == NULL)return 1;
  845. if (m_pParent->m_Runingmode)return 1;
  846. if (m_bShowEffect)return 1;
  847. if (m_bauto)
  848. {
  849. m_bauto = 0;
  850. KillTimer(1);
  851. m_dlg.TerminateThread();
  852. m_dlg.ShowWindow(SW_HIDE);
  853. }
  854. if (m_pCurShowImg)
  855. {
  856. m_bShowEffect = 1;
  857. CutPhoto2();
  858. // ShowEffectDlg dlg;
  859. // dlg.DoModal();
  860. m_bShowEffect = 0;
  861. }
  862. return 1;
  863. case VK_F3:
  864. AutoPic();
  865. break;
  866. case VK_UP:
  867. Rotate1();
  868. return 1;
  869. case VK_PRIOR:
  870. case VK_LEFT:
  871. Pre();
  872. return 1;
  873. case VK_DOWN:
  874. Rotate2();
  875. return 1;
  876. case VK_RIGHT:
  877. case VK_NEXT:
  878. Next();
  879. return 1;
  880. case VK_SHIFT:
  881. {
  882. if (m_bauto)return 1; if (m_bProcessing)return 1;
  883. if (m_pPathArrayBigsize && m_bChooseBig == 0)
  884. {
  885. HANDLE handle = Lock("shgenimagethread");
  886. for (int n = 0; n < m_nPosArray.GetSize(); n++)
  887. {
  888. if (m_nCurImgPos == m_nPosArray.ElementAt(n))
  889. {
  890. delete m_AryOfImgPtr.ElementAt(n);
  891. delete m_AryOfSmallImgPtr.ElementAt(n);
  892. m_AryOfImgPtr.RemoveAt(n);
  893. m_AryOfSmallImgPtr.RemoveAt(n);
  894. m_nPosArray.RemoveAt(n);
  895. break;
  896. }
  897. }
  898. Unlock(handle);
  899. m_bChooseBig = 1;
  900. LoadImage();
  901. }
  902. }
  903. return 1;
  904. case VK_DELETE:
  905. if (m_bauto)return 1;
  906. if (m_pParent)
  907. {
  908. if (m_bProcessing)return 1;
  909. m_bProcessing = 1;
  910. ::SetForegroundWindow(m_hWnd);
  911. if (m_pParent)
  912. {
  913. for (int i = 0; i < m_pParent->m_List1.GetItemCount(); i++)
  914. {
  915. m_pParent->m_List1.SetItemState(i, 0, -1);
  916. }
  917. m_pParent->m_List1.SetItemState(m_nCurImgPos, LVIS_SELECTED, LVIS_SELECTED);
  918. }
  919. // HANDLE handle=Lock("shgenimagethread");
  920. if (m_pParent->OnDel())
  921. {
  922. TerminateThread();
  923. ::SetForegroundWindow(m_hWnd);
  924. m_pCurShowImg = m_pCurShowSmallImg = NULL;
  925. for (int n = m_nPosArray.GetSize() - 1; n >= 0; n--)
  926. {
  927. //if(m_pos==m_nPosArray.ElementAt (n))
  928. {
  929. delete m_AryOfImgPtr.ElementAt(n);
  930. delete m_AryOfSmallImgPtr.ElementAt(n);
  931. m_AryOfImgPtr.RemoveAt(n);
  932. m_AryOfSmallImgPtr.RemoveAt(n);
  933. m_nPosArray.RemoveAt(n);
  934. }
  935. }
  936. if (m_pPathArrayBigsize)
  937. {
  938. m_pPathArrayBigsize->RemoveAll();
  939. m_AryOfImgPath->RemoveAll();
  940. CStringArray *pArray = m_pParent->GetCurArray(m_pParent->m_SelectCategory);
  941. m_pPathArrayBigsize->Copy(*pArray);
  942. for (int i = 0; i < m_pPathArrayBigsize->GetSize(); i++)
  943. {
  944. CString str = m_pPathArrayBigsize->ElementAt(i);
  945. CString spath = str.Left(str.ReverseFind('\\') + 1);
  946. spath += "m";
  947. spath += str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
  948. if (::PathFileExists(spath))
  949. m_AryOfImgPath->Add(spath);
  950. else
  951. m_AryOfImgPath->Add(str);
  952. }
  953. }
  954. if (m_nCurImgPos >= this->m_AryOfImgPath->GetSize())
  955. m_nCurImgPos = 0;
  956. // Unlock(handle);
  957. RunPicThread();
  958. LoadImage();
  959. m_pParent->m_List1.SetItemState(m_nCurImgPos, LVIS_SELECTED, LVIS_SELECTED);
  960. }
  961. m_bProcessing = 0;
  962. return 1;
  963. }
  964. }
  965. ::SetForegroundWindow(m_hWnd);
  966. }
  967. return CDialog::PreTranslateMessage(pMsg);
  968. }
  969. //---------------------------------------------------------------
  970. // Remark by Jeff 2014.11.05
  971. // 函数:OnRButtonDown
  972. // 描述:鼠标右键
  973. // 参数:
  974. // nFlags:表示各种虚拟按键是否下降
  975. // point: 指定x和光标的y坐标
  976. // 返回:无
  977. //---------------------------------------------------------------
  978. void ShowPic22::OnRButtonDown(UINT nFlags, CPoint point) // 鼠标右键;
  979. {
  980. if (m_bauto)return;
  981. if (m_bProcessing)return;
  982. if (m_pParent)
  983. {
  984. for (int i = 0; i < m_pParent->m_List1.GetItemCount(); i++)
  985. {
  986. m_pParent->m_List1.SetItemState(i, 0, -1);
  987. }
  988. m_pParent->m_List1.SetItemState(m_nCurImgPos, LVIS_SELECTED, LVIS_SELECTED);
  989. m_pParent->OnRclickList1();
  990. }
  991. CDialog::OnRButtonDown(nFlags, point);
  992. }
  993. //---------------------------------------------------------------
  994. // Remark by Jeff 2014.11.05
  995. // 函数:AutoPic
  996. // 描述:播放幻灯片按钮
  997. // 参数:无
  998. // 返回:无
  999. //---------------------------------------------------------------
  1000. void ShowPic22::AutoPic() // 自动播放幻灯片按钮;
  1001. {
  1002. try
  1003. {
  1004. if (m_bProcessing)
  1005. return;
  1006. m_dlg.m_effect = m_PicBar.m_nType;
  1007. m_bauto = !m_bauto;
  1008. m_PicBar.ChangeBtn();
  1009. if (m_bauto)
  1010. {
  1011. m_PreviewDlg.ShowMin();
  1012. if (m_nCurImgPos >= this->m_AryOfImgPath->GetSize())
  1013. m_nCurImgPos = 0;
  1014. LoadImage();
  1015. }
  1016. else
  1017. {
  1018. KillTimer(1);
  1019. m_dlg.TerminateThread();
  1020. m_dlg.ShowWindow(SW_HIDE);
  1021. }
  1022. ::SetForegroundWindow(m_hWnd);
  1023. }
  1024. catch (...)
  1025. {
  1026. }
  1027. }
  1028. void ShowPic22::OnTimer(UINT nIDEvent)
  1029. {
  1030. try
  1031. {
  1032. if (m_bShowEffect)
  1033. return;
  1034. ::SetForegroundWindow(m_hWnd);
  1035. if (nIDEvent == 1)
  1036. {// 自动播放相片;
  1037. KillTimer(1);
  1038. m_nCurImgPos++;
  1039. if (m_nCurImgPos >= this->m_AryOfImgPath->GetSize())
  1040. {
  1041. KillTimer(1);
  1042. m_dlg.TerminateThread();
  1043. m_dlg.ShowWindow(SW_HIDE);
  1044. m_PicBar.ChangeBtn();
  1045. AfxMessageBox(_T("您的照片已浏览完毕!"), MB_ICONINFORMATION);
  1046. m_bauto = FALSE;
  1047. m_bProcessing = FALSE;
  1048. m_nCurImgPos -= 2;
  1049. Next();
  1050. return;
  1051. }
  1052. LoadImage();
  1053. }
  1054. else if (nIDEvent == 2)
  1055. {// 鼠标滚动轴事件引起,放大或缩小图片;
  1056. KillTimer(2);
  1057. if (m_pImagetemp)
  1058. {
  1059. if (m_rcImgShow.Width() > m_pImagetemp->GetWidth())
  1060. {
  1061. DELETEP(m_pImagetemp)
  1062. m_pImagetemp = m_pCurShowImg->GetThumbnailImage(min(m_pCurShowImg->GetWidth(), m_rcImgShow.Width()), min(m_pCurShowImg->GetHeight(), m_rcImgShow.Height()), NULL, NULL);
  1063. Graphics graphic(m_pImagetemp);//防止GetThumbnailImage影响质量
  1064. graphic.DrawImage(m_pCurShowImg, 0, 0, m_pImagetemp->GetWidth(), m_pImagetemp->GetHeight());
  1065. }
  1066. }
  1067. else
  1068. {
  1069. m_pImagetemp = m_pCurShowImg->GetThumbnailImage(min(m_pCurShowImg->GetWidth(), m_rcImgShow.Width()), min(m_pCurShowImg->GetHeight(), m_rcImgShow.Height()), NULL, NULL);
  1070. Graphics graphic(m_pImagetemp);//防止GetThumbnailImage影响质量
  1071. graphic.DrawImage(m_pCurShowImg, 0, 0, m_pImagetemp->GetWidth(), m_pImagetemp->GetHeight());
  1072. }
  1073. Invalidate();
  1074. }
  1075. else if (nIDEvent == 3)
  1076. {
  1077. KillTimer(3);
  1078. CPoint pt;
  1079. ::GetCursorPos(&pt);
  1080. if (m_picbarrc.PtInRect(pt))
  1081. {
  1082. SetTimer(3, 1500, NULL);
  1083. }
  1084. else
  1085. m_PicBar.ShowWindow(SW_HIDE);
  1086. ::SetForegroundWindow(m_hWnd);
  1087. }
  1088. else if (nIDEvent == 4)
  1089. {
  1090. KillTimer(4);
  1091. m_PicBar.SetLiaPath("4.lia");
  1092. m_PicBar.Create(IDD_DLGmydlg, this);
  1093. if (m_PicBar.m_bInit)
  1094. {
  1095. m_PicBar.m_pParent = this;
  1096. int hei;
  1097. m_PicBar.GetWindowRect(m_picbarrc);
  1098. hei = m_picbarrc.Height();
  1099. m_picbarrc.bottom = g_screenhei - 10;
  1100. m_picbarrc.top = m_picbarrc.bottom - hei;
  1101. m_PicBar.MoveWindow(m_picbarrc);
  1102. SetTimer(3, 1500, NULL);
  1103. m_startpt2.x = m_startpt2.y = 0;
  1104. }
  1105. ::SetForegroundWindow(m_hWnd);
  1106. }
  1107. else if (nIDEvent == 5)
  1108. {
  1109. KillTimer(5);
  1110. LoadImage();
  1111. }
  1112. else if (nIDEvent == 6)
  1113. {
  1114. if (m_bProcessing)return;
  1115. m_bProcessing = 1;
  1116. g_nSendCode = 0;
  1117. TerminateThread();
  1118. m_dlg.TerminateThread();
  1119. CDialog::OnOK();
  1120. m_bProcessing = 0;
  1121. }
  1122. }
  1123. catch (...)
  1124. {
  1125. }
  1126. }
  1127. void ShowPic22::OnClose()
  1128. {
  1129. if (m_pParent)
  1130. {
  1131. if (m_bProcessing)return;
  1132. m_bProcessing = 1;
  1133. {
  1134. TerminateThread();
  1135. ::SetForegroundWindow(m_hWnd);
  1136. m_pCurShowImg = m_pCurShowSmallImg = NULL;
  1137. for (int n = m_nPosArray.GetSize() - 1; n >= 0; n--)
  1138. {
  1139. delete m_AryOfImgPtr.ElementAt(n);
  1140. delete m_AryOfSmallImgPtr.ElementAt(n);
  1141. m_AryOfImgPtr.RemoveAt(n);
  1142. m_AryOfSmallImgPtr.RemoveAt(n);
  1143. m_nPosArray.RemoveAt(n);
  1144. }
  1145. if (m_pPathArrayBigsize)
  1146. {
  1147. m_pPathArrayBigsize->RemoveAll();
  1148. m_AryOfImgPath->RemoveAll();
  1149. CStringArray *pArray = m_pParent->GetCurArray(m_pParent->m_SelectCategory);
  1150. m_pPathArrayBigsize->Copy(*pArray);
  1151. for (int i = 0; i < m_pPathArrayBigsize->GetSize(); i++)
  1152. {
  1153. CString str = m_pPathArrayBigsize->ElementAt(i);
  1154. CString spath = str.Left(str.ReverseFind('\\') + 1);
  1155. spath += "m";
  1156. spath += str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
  1157. if (::PathFileExists(spath))
  1158. m_AryOfImgPath->Add(spath);
  1159. else
  1160. m_AryOfImgPath->Add(str);
  1161. }
  1162. }
  1163. if (m_nCurImgPos >= this->m_AryOfImgPath->GetSize())
  1164. m_nCurImgPos = 0;
  1165. if (this->m_AryOfImgPath->GetSize() == 0)
  1166. {
  1167. m_bProcessing = 0;
  1168. KillTimer(6);
  1169. SetTimer(6, 100, NULL);
  1170. }
  1171. else
  1172. {
  1173. RunPicThread();
  1174. LoadImage();
  1175. }
  1176. }
  1177. m_bProcessing = 0;
  1178. }
  1179. }
  1180. void ShowPic22::InitRc()
  1181. {
  1182. try
  1183. {
  1184. if (m_pCurShowImg == NULL)
  1185. return;
  1186. CRect rc;
  1187. GetClientRect(rc);
  1188. m_rcImgShow = rc;
  1189. int width, height;
  1190. if (m_pCurShowSmallImg)
  1191. {
  1192. width = m_pCurShowSmallImg->GetWidth();
  1193. height = m_pCurShowSmallImg->GetHeight();
  1194. }
  1195. else
  1196. {
  1197. width = m_pCurShowImg->GetWidth();
  1198. height = m_pCurShowImg->GetHeight();
  1199. }
  1200. //////////
  1201. float fscale = (float)width / (float)height;
  1202. float rcscale = ((float)m_rcImgShow.Width()) / ((float)m_rcImgShow.Height());
  1203. int rcwid = m_rcImgShow.Width();
  1204. int rchei = m_rcImgShow.Height();
  1205. int dt = 0;
  1206. if (rcscale < fscale)
  1207. {
  1208. dt = (rchei - rcwid / fscale) / 2;
  1209. m_rcImgShow.top += dt;
  1210. m_rcImgShow.bottom -= dt;
  1211. }
  1212. else
  1213. {
  1214. dt = (rcwid - rchei*fscale) / 2;
  1215. m_rcImgShow.left += dt;
  1216. m_rcImgShow.right -= dt;
  1217. }
  1218. m_rcImgShowBack = m_rcImgShow;
  1219. }
  1220. catch (...)
  1221. {
  1222. }
  1223. }
  1224. //---------------------------------------------------------------
  1225. // Remark by Jeff 2014.11.05
  1226. // 函数:Rotate1
  1227. // 描述:旋转相片270度;
  1228. // 参数:无
  1229. // 返回:无
  1230. //---------------------------------------------------------------
  1231. void ShowPic22::Rotate1() // 逆时针旋转相片按钮;
  1232. {
  1233. if (m_bauto)return;
  1234. if (m_bProcessing)return;
  1235. try
  1236. {
  1237. if (m_pCurShowImg)
  1238. {
  1239. m_pCurShowImg->RotateFlip(Rotate270FlipNone);
  1240. if (m_pCurShowSmallImg)
  1241. m_pCurShowSmallImg->RotateFlip(Rotate270FlipNone);
  1242. if (m_pImagetemp)
  1243. m_pImagetemp->RotateFlip(Rotate270FlipNone);
  1244. InitRc();
  1245. Invalidate();
  1246. }
  1247. }
  1248. catch (...)
  1249. {
  1250. }
  1251. }
  1252. //---------------------------------------------------------------
  1253. // Remark by Jeff 2014.11.05
  1254. // 函数:Rotate2
  1255. // 描述:旋转相片90度;
  1256. // 参数:无
  1257. // 返回:无
  1258. //---------------------------------------------------------------
  1259. void ShowPic22::Rotate2() // 顺时针旋转相片按钮;
  1260. {
  1261. if (m_bauto)return;
  1262. if (m_bProcessing)return;
  1263. try
  1264. {
  1265. if (m_pCurShowImg)
  1266. {
  1267. m_pCurShowImg->RotateFlip(Rotate90FlipNone);
  1268. if (m_pCurShowSmallImg)
  1269. m_pCurShowSmallImg->RotateFlip(Rotate90FlipNone);
  1270. if (m_pImagetemp)
  1271. m_pImagetemp->RotateFlip(Rotate90FlipNone);
  1272. InitRc();
  1273. Invalidate();
  1274. }
  1275. }
  1276. catch (...)
  1277. {
  1278. }
  1279. }
  1280. //---------------------------------------------------------------
  1281. // Remark by Jeff 2014.11.05
  1282. // 函数:Pre
  1283. // 描述:上一张按钮
  1284. // 参数:无
  1285. // 返回:无
  1286. //---------------------------------------------------------------
  1287. void ShowPic22::Pre() // 上一张按钮;
  1288. {
  1289. if (m_bauto)return;
  1290. if (m_bProcessing)return;
  1291. m_bInit = 1;
  1292. try
  1293. {
  1294. m_nCurImgPos--;
  1295. if (m_nCurImgPos < 0)
  1296. m_nCurImgPos = this->m_AryOfImgPath->GetSize() - 1;
  1297. m_bChooseBig = 0;
  1298. LoadImage();
  1299. m_PreviewDlg.ShowPic(m_nCurImgPos);
  1300. }
  1301. catch (...)
  1302. {
  1303. }
  1304. }
  1305. //---------------------------------------------------------------
  1306. // Remark by Jeff 2014.11.05
  1307. // 函数:Next
  1308. // 描述:下一张按钮
  1309. // 参数:无
  1310. // 返回:无
  1311. //---------------------------------------------------------------
  1312. void ShowPic22::Next() // 下一张按钮;
  1313. {
  1314. if (m_bauto)return;
  1315. if (m_bProcessing)return;
  1316. m_bInit = 1;
  1317. try
  1318. {
  1319. m_nCurImgPos++;
  1320. if (m_nCurImgPos >= this->m_AryOfImgPath->GetSize())
  1321. {
  1322. m_nCurImgPos = 0;
  1323. AfxMessageBox("您的照片已浏览完毕!", MB_ICONINFORMATION);
  1324. }
  1325. m_bChooseBig = 0;
  1326. LoadImage();
  1327. m_PreviewDlg.ShowPic(m_nCurImgPos);
  1328. }
  1329. catch (...)
  1330. {
  1331. }
  1332. }
  1333. //------------------------------------------------------
  1334. // Remark by Jeff 2014.11.05
  1335. // 函数:SetEffect
  1336. // 描述:设置显示相片效果;
  1337. // 参数:effect:效果类型;
  1338. // 返回:无
  1339. //------------------------------------------------------
  1340. void ShowPic22::SetEffect(int effect)
  1341. {
  1342. ::SetForegroundWindow(m_hWnd);
  1343. m_dlg.m_effect = effect;
  1344. }
  1345. void ShowPic22::TerminateThread()
  1346. {
  1347. try
  1348. {
  1349. if (m_bRunning)
  1350. {
  1351. m_bTerminate = true;
  1352. for (;;)
  1353. {
  1354. if (::WaitForSingleObject(m_hThread, 0) == WAIT_OBJECT_0)
  1355. break;
  1356. MSG msg;
  1357. while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
  1358. {
  1359. if (!AfxGetApp()->PumpMessage())
  1360. break;
  1361. }
  1362. }
  1363. ::CloseHandle(m_hThread);
  1364. }
  1365. }
  1366. catch (...)
  1367. {
  1368. }
  1369. }
  1370. void ShowPic22::InitRc(Image *img, CRect &rc)
  1371. {
  1372. try
  1373. {
  1374. if (img == NULL)return;
  1375. CRect rc2;
  1376. GetClientRect(rc2);
  1377. rc = rc2;
  1378. int width, height;
  1379. width = img->GetWidth();
  1380. height = img->GetHeight();
  1381. //////////
  1382. float fscale = (float)width / (float)height;
  1383. float rcscale = ((float)rc.Width()) / ((float)rc.Height());
  1384. int rcwid = rc.Width();
  1385. int rchei = rc.Height();
  1386. int dt = 0;
  1387. if (rcscale < fscale)
  1388. {
  1389. dt = (rchei - rcwid / fscale) / 2;
  1390. rc.top += dt;
  1391. rc.bottom -= dt;
  1392. }
  1393. else
  1394. {
  1395. dt = (rcwid - rchei*fscale) / 2;
  1396. rc.left += dt;
  1397. rc.right -= dt;
  1398. }
  1399. }
  1400. catch (...)
  1401. {
  1402. }
  1403. }
  1404. HBRUSH ShowPic22::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  1405. {
  1406. HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  1407. if (nCtlColor == CTLCOLOR_STATIC)
  1408. {
  1409. pDC->SetBkMode(TRANSPARENT);
  1410. pDC->SetTextColor(RGB(255, 255, 255));
  1411. return (HBRUSH)::GetStockObject(NULL_BRUSH);
  1412. }
  1413. return hbr;
  1414. }
  1415. void ShowPic22::RunPicThread()
  1416. {
  1417. // 1.是否有播放相片路径;
  1418. if (m_AryOfImgPath->GetSize() == 0)
  1419. return;//2011-03-09
  1420. TerminateThread();
  1421. m_hThread = (HANDLE)_beginthreadex(NULL, 0, GenThumbImgThread, (LPVOID)this, 0/* CREATE_SUSPENDED*/, &m_dwThreadID);
  1422. m_bRunning = true;
  1423. }
  1424. //-------------------------------------------------------------------
  1425. // Remark by Jeff
  1426. // 函数:OnMouseWheel2
  1427. // 描述:鼠标滚轮缩放图片
  1428. // 参数:bZoomOut : TRUE 表示放大;FALSE表示缩小;
  1429. // 返回:无
  1430. //-------------------------------------------------------------------
  1431. void ShowPic22::OnMouseWheel2(BOOL bZoomOut) // 鼠标滚轮缩放图片;
  1432. {
  1433. if (m_pCurShowImg == NULL)return;
  1434. if (m_bauto)return;
  1435. if (m_bProcessing)return;
  1436. m_bScroll = 1;
  1437. if (bZoomOut)
  1438. {
  1439. // if(m_fscale>4)return 1;
  1440. m_fscale *= 1.2;
  1441. int dtx = (m_fscale*m_rcImgShowBack.Width() - m_rcImgShow.Width()) / 2.0;
  1442. int dty = (m_fscale*m_rcImgShowBack.Height() - m_rcImgShow.Height()) / 2.0;
  1443. m_rcImgShow.left -= dtx;
  1444. m_rcImgShow.right += dtx;
  1445. m_rcImgShow.top -= dty;
  1446. m_rcImgShow.bottom += dty;
  1447. Invalidate();
  1448. }
  1449. else
  1450. {
  1451. if (m_fscale <= 1)return;
  1452. m_fscale /= 1.2;
  1453. if (m_fscale < 1)m_fscale = 1;
  1454. int dtx = (m_fscale*m_rcImgShowBack.Width() - m_rcImgShow.Width()) / 2.0;
  1455. int dty = (m_fscale*m_rcImgShowBack.Height() - m_rcImgShow.Height()) / 2.0;
  1456. m_rcImgShow.left -= dtx;
  1457. m_rcImgShow.right += dtx;
  1458. m_rcImgShow.top -= dty;
  1459. m_rcImgShow.bottom += dty;
  1460. if (m_rcImgShowBack.Height() == m_rcScreen.Height())
  1461. {
  1462. if (m_rcImgShow.top < m_rcScreen.top && m_rcImgShow.bottom < m_rcScreen.bottom)
  1463. {
  1464. dtx = m_rcScreen.bottom - m_rcImgShow.bottom;
  1465. m_rcImgShow.top += dtx;
  1466. m_rcImgShow.bottom += dtx;
  1467. }
  1468. else if (m_rcImgShow.top >m_rcScreen.top && m_rcImgShow.bottom > m_rcScreen.bottom)
  1469. {
  1470. dtx = m_rcImgShow.top - m_rcScreen.top;
  1471. m_rcImgShow.top -= dtx;
  1472. m_rcImgShow.bottom -= dtx;
  1473. }
  1474. dtx = m_rcImgShow.Width();
  1475. m_rcImgShow.left = (m_rcScreen.Width() - dtx) / 2;
  1476. m_rcImgShow.right = m_rcImgShow.left + dtx;
  1477. }
  1478. if (m_rcImgShowBack.Width() == m_rcScreen.Width())
  1479. {
  1480. if (m_rcImgShow.left < m_rcScreen.left && m_rcImgShow.right < m_rcScreen.right)
  1481. {
  1482. dtx = m_rcScreen.right - m_rcImgShow.right;
  1483. m_rcImgShow.left += dtx;
  1484. m_rcImgShow.right += dtx;
  1485. }
  1486. else if (m_rcImgShow.left >m_rcScreen.left && m_rcImgShow.right > m_rcScreen.right)
  1487. {
  1488. dtx = m_rcImgShow.left - m_rcScreen.left;
  1489. m_rcImgShow.left -= dtx;
  1490. m_rcImgShow.right -= dtx;
  1491. }
  1492. dtx = m_rcImgShow.Height();
  1493. m_rcImgShow.top = (m_rcScreen.Height() - dtx) / 2;
  1494. m_rcImgShow.bottom = m_rcImgShow.top + dtx;
  1495. }
  1496. Invalidate();
  1497. }
  1498. KillTimer(2);
  1499. SetTimer(2, 100, NULL);
  1500. }
  1501. long ShowPic22::ShowInfo2(WPARAM inWParam, LPARAM inLParam)
  1502. {
  1503. if (inWParam == 1)
  1504. {
  1505. if (m_bauto)AutoPic();
  1506. return 1;
  1507. }
  1508. ShowInfo();
  1509. return 1;
  1510. }
  1511. void ShowPic22::ShowInfo()
  1512. {
  1513. Invalidate();
  1514. if (m_bShowImgInfo)
  1515. {
  1516. CString str = m_AryOfImgPath->ElementAt(m_nCurImgPos);
  1517. str = str.Right(str.GetLength() - str.ReverseFind(_T('\\')) - 1);
  1518. str = str.Left(str.GetLength() - 4);
  1519. str.TrimLeft(_T("m"));
  1520. str = _T("编号:") + str + _T(" ");
  1521. if (m_pParent)
  1522. str += m_pParent->GetZSInfo(m_nCurImgPos);
  1523. SetDlgItemText(IDC_STATIC2, str);
  1524. }
  1525. }
  1526. //----------------------------------------------------------------
  1527. // Remark by Jeff 2014.11.05
  1528. // 函数:CutPhoto2
  1529. // 描述:剪裁按钮对应的剪裁功能;
  1530. // 参数:无
  1531. // 返回:无
  1532. // ----------------------------------------------------------------
  1533. void ShowPic22::CutPhoto2()
  1534. {
  1535. if (m_pParent == NULL)return;
  1536. CutPhoto dlg;
  1537. CString path = m_AryOfImgPath->ElementAt(m_nCurImgPos);
  1538. if (m_pPathArrayBigsize)path = m_pPathArrayBigsize->ElementAt(m_nCurImgPos);
  1539. path = path.Right(path.GetLength() - path.ReverseFind('\\') - 1);
  1540. path = path.Left(path.Find("."));
  1541. // path其实不是路径,只是文件名;如005
  1542. dlg.m_strImgName = path;
  1543. dlg.m_photowidth = m_pCurShowImg->GetWidth();
  1544. dlg.m_photoheight = m_pCurShowImg->GetHeight();
  1545. dlg.m_pImg = m_pCurShowSmallImg;
  1546. dlg.m_strOrderNumber = m_pParent->m_strOrderNumber;
  1547. dlg.DoModal();
  1548. }
  1549. //----------------------------------------------------------------
  1550. // Remark by Jeff 2014.11.05
  1551. // 函数:CutPhoto3
  1552. // 描述:剪裁按钮;
  1553. // 参数:无
  1554. // 返回:无
  1555. // ----------------------------------------------------------------
  1556. void ShowPic22::CutPhoto3()
  1557. {
  1558. if (m_pParent == NULL)return;
  1559. if (m_pParent->m_Runingmode)return;
  1560. if (m_bShowEffect)return;
  1561. if (m_bauto)
  1562. {
  1563. m_bauto = 0;
  1564. KillTimer(1);
  1565. m_dlg.TerminateThread();
  1566. m_dlg.ShowWindow(SW_HIDE);
  1567. }
  1568. if (m_pCurShowImg)
  1569. {
  1570. m_bShowEffect = 1;
  1571. CutPhoto2();
  1572. m_bShowEffect = 0;
  1573. }
  1574. }