ShowPic22.cpp 40 KB

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