ShowEffect.cpp 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423
  1. // ShowEffectDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "ShowEffect.h"
  6. #include <math.h>
  7. #include "InputName.h"
  8. #define THUMBNAIL_WIDTH 60
  9. #define THUMBNAIL_HEIGHT 50
  10. /////////////////////////////////////////////////////////////////////////////
  11. // ShowEffectDlg dialog
  12. ShowEffectDlg::ShowEffectDlg(CWnd* pParent /*=NULL*/)
  13. : CDialog(ShowEffectDlg::IDD, pParent)
  14. {
  15. //{{AFX_DATA_INIT(ShowEffectDlg)
  16. // NOTE: the ClassWizard will add member initialization here
  17. m_pbmp=NULL;
  18. m_pImage=NULL;
  19. m_pImagebak=NULL;
  20. m_pPhoto=NULL;
  21. //}}AFX_DATA_INIT
  22. m_effectpos=0;
  23. m_photopos=0;
  24. m_fscale=1.0;
  25. m_bTerminate=false;
  26. m_bRunning=false;
  27. m_hThread = NULL;
  28. m_bTerminate2=false;
  29. m_bRunning2=false;
  30. m_hThread2 = NULL;
  31. m_bLoadEffect=1;
  32. m_bLoadPhoto=1;
  33. }
  34. void ShowEffectDlg::DoDataExchange(CDataExchange* pDX)
  35. {
  36. CDialog::DoDataExchange(pDX);
  37. //{{AFX_DATA_MAP(ShowEffectDlg)
  38. DDX_Control(pDX, IDC_LIST2, m_List2);
  39. DDX_Control(pDX, IDC_LIST1, m_List1);
  40. //}}AFX_DATA_MAP
  41. }
  42. BEGIN_MESSAGE_MAP(ShowEffectDlg, CDialog)
  43. //{{AFX_MSG_MAP(ShowEffectDlg)
  44. ON_WM_DESTROY()
  45. ON_WM_PAINT()
  46. ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  47. ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
  48. ON_WM_LBUTTONDOWN()
  49. ON_WM_MOUSEMOVE()
  50. ON_WM_LBUTTONUP()
  51. ON_WM_MOUSEWHEEL()
  52. ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
  53. ON_WM_TIMER()
  54. ON_NOTIFY(NM_CLICK, IDC_LIST2, OnClickList2)
  55. //}}AFX_MSG_MAP
  56. END_MESSAGE_MAP()
  57. // ON_WM_ERASEBKGND()
  58. /////////////////////////////////////////////////////////////////////////////
  59. // ShowEffectDlg message handlers
  60. unsigned __stdcall LoadThumbNail17(LPVOID lpParam)
  61. {
  62. try
  63. {
  64. ShowEffectDlg *pDlg=(ShowEffectDlg*)lpParam;
  65. CListCtrl *ListCtrl=&pDlg->m_List2;
  66. CImageList* pImgList=&pDlg->m_ImageListThumb2;
  67. // reset our image list
  68. for(int i=0; i<pImgList->GetImageCount(); i++)
  69. pImgList->Remove(i);
  70. // remove all items from list view
  71. ListCtrl->DeleteAllItems();
  72. pImgList->SetImageCount(pDlg->m_vFileName2.size());
  73. TCHAR path[MAX_PATH];
  74. vector<CString>::iterator iter;
  75. // Set redraw to FALSE to avoid flickering during adding new items
  76. ListCtrl->SetRedraw(FALSE);
  77. int nIndex=0;
  78. CString str, spath;
  79. for(iter=pDlg->m_vFileName2.begin(); iter!=pDlg->m_vFileName2.end() && pDlg->m_bTerminate2!=true; iter++, nIndex++)
  80. {
  81. str=*iter;
  82. str=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
  83. str=str.Left (str.Find ("."));
  84. ListCtrl->InsertItem(nIndex, str, nIndex);
  85. }
  86. ListCtrl->SetRedraw(TRUE);
  87. ListCtrl->Invalidate();
  88. const float fRatio=(float)THUMBNAIL_HEIGHT/THUMBNAIL_WIDTH;
  89. int XDest, YDest, nDestWidth, nDestHeight;
  90. nIndex=0;
  91. SolidBrush whitebrush(Color(255,255,255,255));
  92. for(iter=pDlg->m_vFileName2.begin(); iter!=pDlg->m_vFileName2.end() && pDlg->m_bTerminate2!=true; iter++, nIndex++)
  93. {
  94. // Load Image File
  95. Image *image=NULL;
  96. Bitmap *pBmp=NULL;
  97. str=*iter;
  98. spath=str.Left (str.ReverseFind ('\\')+1);
  99. spath+="s";
  100. spath+=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
  101. if (PathFileExists(spath))
  102. ::LoadImageFromBuf (&image, spath);
  103. else
  104. ::LoadImageFromBuf (&image, str);
  105. int orientation=GetOrientation(image);
  106. if(orientation==8)
  107. image->RotateFlip( Rotate270FlipNone );
  108. else if(orientation==6)
  109. image->RotateFlip( Rotate90FlipNone );
  110. if(image->GetWidth()==0)
  111. continue;
  112. // Calculate Rect to fit to canvas
  113. const float fImgRatio=(float)image->GetHeight()/image->GetWidth();
  114. if(fImgRatio > fRatio)
  115. {
  116. nDestWidth=THUMBNAIL_HEIGHT/fImgRatio;
  117. XDest=(THUMBNAIL_WIDTH-nDestWidth)/2;
  118. YDest=0;
  119. nDestHeight=THUMBNAIL_HEIGHT;
  120. }
  121. else
  122. {
  123. XDest=0;
  124. nDestWidth=THUMBNAIL_WIDTH;
  125. nDestHeight=THUMBNAIL_WIDTH*fImgRatio;
  126. YDest=(THUMBNAIL_HEIGHT-nDestHeight)/2;
  127. }
  128. pBmp=new Bitmap(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, PixelFormat24bppRGB );
  129. Graphics graph2(pBmp);
  130. graph2.Clear(Color(255,192,192,192));
  131. graph2.FillRectangle (&whitebrush,1, 1, THUMBNAIL_WIDTH-2, THUMBNAIL_HEIGHT-2);
  132. Graphics graph(pBmp);
  133. Rect desRect(XDest, YDest, nDestWidth, nDestHeight);
  134. // Draw Image
  135. graph.DrawImage(image, desRect, 0,0,image->GetWidth(),image->GetHeight(),UnitPixel);
  136. delete image;
  137. // Attach to Bitmap and Replace image in CImageList
  138. CBitmap bitmap;
  139. HBITMAP hbmp;
  140. pBmp->GetHBITMAP(Color(255,255,255,255), &hbmp);
  141. bitmap.Attach(hbmp);
  142. pImgList->Replace(nIndex, &bitmap, NULL);
  143. delete pBmp;
  144. // Redraw only a current item for removing flickering and fast speed.
  145. ListCtrl->RedrawItems(nIndex, nIndex);
  146. // Release used DC and Object
  147. }
  148. ListCtrl->Invalidate();
  149. pDlg->m_bRunning2=false;
  150. pDlg->m_bTerminate2=false;
  151. _endthreadex( 0 );
  152. return 0;
  153. }
  154. catch(...)
  155. {
  156. }
  157. }
  158. unsigned __stdcall LoadThumbNail16(LPVOID lpParam)
  159. {
  160. try
  161. {
  162. ShowEffectDlg *pDlg=(ShowEffectDlg*)lpParam;
  163. CListCtrl *ListCtrl=&pDlg->m_List1;
  164. CImageList* pImgList=&pDlg->m_ImageListThumb;
  165. // reset our image list
  166. for(int i=0; i<pImgList->GetImageCount(); i++)
  167. pImgList->Remove(i);
  168. // remove all items from list view
  169. ListCtrl->DeleteAllItems();
  170. pImgList->SetImageCount(pDlg->m_vFileName.size());
  171. TCHAR path[MAX_PATH];
  172. vector<CString>::iterator iter;
  173. // Set redraw to FALSE to avoid flickering during adding new items
  174. ListCtrl->SetRedraw(FALSE);
  175. int nIndex=0;
  176. CString str, spath;
  177. for(iter=pDlg->m_vFileName.begin(); iter!=pDlg->m_vFileName.end() && pDlg->m_bTerminate!=true; iter++, nIndex++)
  178. {
  179. str=*iter;
  180. str=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
  181. str=str.Left (str.Find ("."));
  182. ListCtrl->InsertItem(nIndex, str, nIndex);
  183. }
  184. ListCtrl->SetRedraw(TRUE);
  185. ListCtrl->Invalidate();
  186. const float fRatio=(float)THUMBNAIL_HEIGHT/THUMBNAIL_WIDTH;
  187. int XDest, YDest, nDestWidth, nDestHeight;
  188. nIndex=0;
  189. SolidBrush whitebrush(Color(255,255,255,255));
  190. for(iter=pDlg->m_vFileName.begin(); iter!=pDlg->m_vFileName.end() && pDlg->m_bTerminate!=true; iter++, nIndex++)
  191. {
  192. // Load Image File
  193. Image *image=NULL;
  194. Bitmap *pBmp=NULL;
  195. str=*iter;
  196. spath=str.Left (str.ReverseFind ('\\')+1);
  197. spath+="s";
  198. spath+=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
  199. spath.Replace ("png","jpg");
  200. if (PathFileExists(spath))
  201. {
  202. ::LoadImageFromBuf (&image, spath);
  203. }
  204. else
  205. ::LoadImageFromBuf (&image, str);
  206. int orientation=GetOrientation(image);
  207. if(orientation==8)
  208. image->RotateFlip( Rotate270FlipNone );
  209. else if(orientation==6)
  210. image->RotateFlip( Rotate90FlipNone );
  211. if(image->GetWidth()==0)
  212. continue;
  213. // Calculate Rect to fit to canvas
  214. const float fImgRatio=(float)image->GetHeight()/image->GetWidth();
  215. if(fImgRatio > fRatio)
  216. {
  217. nDestWidth=THUMBNAIL_HEIGHT/fImgRatio;
  218. XDest=(THUMBNAIL_WIDTH-nDestWidth)/2;
  219. YDest=0;
  220. nDestHeight=THUMBNAIL_HEIGHT;
  221. }
  222. else
  223. {
  224. XDest=0;
  225. nDestWidth=THUMBNAIL_WIDTH;
  226. nDestHeight=THUMBNAIL_WIDTH*fImgRatio;
  227. YDest=(THUMBNAIL_HEIGHT-nDestHeight)/2;
  228. }
  229. pBmp=new Bitmap(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, PixelFormat24bppRGB );
  230. Graphics graph2(pBmp);
  231. graph2.Clear(Color(255,192,192,192));
  232. graph2.FillRectangle (&whitebrush,1, 1, THUMBNAIL_WIDTH-2, THUMBNAIL_HEIGHT-2);
  233. Graphics graph(pBmp);
  234. Rect desRect(XDest, YDest, nDestWidth, nDestHeight);
  235. // Draw Image
  236. graph.DrawImage(image, desRect, 0,0,image->GetWidth(),image->GetHeight(),UnitPixel);
  237. delete image;
  238. // Attach to Bitmap and Replace image in CImageList
  239. CBitmap bitmap;
  240. HBITMAP hbmp;
  241. pBmp->GetHBITMAP(Color(255,255,255,255), &hbmp);
  242. bitmap.Attach(hbmp);
  243. pImgList->Replace(nIndex, &bitmap, NULL);
  244. delete pBmp;
  245. // Redraw only a current item for removing flickering and fast speed.
  246. ListCtrl->RedrawItems(nIndex, nIndex);
  247. // Release used DC and Object
  248. }
  249. ListCtrl->Invalidate();
  250. pDlg->m_bRunning=false;
  251. pDlg->m_bTerminate=false;
  252. _endthreadex( 0 );
  253. return 0;
  254. }
  255. catch(...)
  256. {
  257. }
  258. }
  259. BOOL ShowEffectDlg::OnInitDialog()
  260. {
  261. CDialog::OnInitDialog();
  262. GetDlgItem(IDC_BUTTON2)->EnableWindow(IsHasRights2new(49));
  263. using namespace helper_coffs;
  264. ffsco o;
  265. o.dirs(0);
  266. o.find(LPCSTR(g_path7), LPCSTR("*.png"));
  267. ffsco::typeT coo;
  268. ffsco::typeT::iterator it;
  269. coo = o.co_file();
  270. for (it = coo.begin(); coo.end() != it; it ++)
  271. {
  272. m_effectpatharray.Add ((*it).c_str());
  273. }
  274. if(m_effectpatharray.GetSize()==0)
  275. {
  276. AfxMessageBox("您还没有安装效果图!", MB_ICONINFORMATION);
  277. ::CreateDirectory (g_path7, NULL);
  278. // CDialog::OnCancel ();
  279. // return false;
  280. }
  281. // TODO: Add extra initialization here
  282. // Jeff.m_rcscreen:屏幕尺寸;
  283. ::SetWindowPos(m_hWnd,HWND_TOP,0 ,0,g_screenwid,g_screenhei,SWP_SHOWWINDOW);
  284. m_rcscreen=CRect(0, 0, g_screenwid, g_screenhei);
  285. // Jeff.rc:临时区域;
  286. // Jeff.rc2:客户区域大小,用于放置PNG效果图;
  287. // Jeff.rc3:按钮区域;
  288. CRect rc,rc2,rc3;
  289. GetClientRect(rc2);
  290. GetDlgItem(IDC_BUTTON1)->GetWindowRect(rc3);
  291. ScreenToClient(rc3);
  292. rc=rc2;
  293. rc.right =110;
  294. rc.top =rc3.bottom +rc3.top;
  295. m_List1.MoveWindow(rc);
  296. rc=rc2;
  297. rc.left=rc.right-110;
  298. m_List2.MoveWindow(rc);
  299. // m_pbmp:最终显示PNG效果图的Bimap对象(PNG+客人相片 合二为一的结果);
  300. rc=rc2;
  301. rc.left +=110;
  302. rc.right -=110;
  303. m_pbmp=new Bitmap(rc.Width (), rc.Height (), PixelFormat24bppRGB );
  304. m_ImageListThumb.Create(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, ILC_COLOR24, 0, 1);
  305. m_List1.SetImageList(&m_ImageListThumb, LVSIL_NORMAL);
  306. m_ImageListThumb2.Create(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, ILC_COLOR24, 0, 1);
  307. m_List2.SetImageList(&m_ImageListThumb2, LVSIL_NORMAL);
  308. if(m_bRunning)return 0;
  309. CStringArray *pArray=&m_effectpatharray;
  310. m_vFileName.clear();
  311. for(int i=0; i<pArray->GetSize (); i++)
  312. {
  313. CString filePath=pArray->ElementAt (i);
  314. filePath.MakeLower();
  315. m_vFileName.push_back(filePath);
  316. }
  317. TerminateThread();
  318. m_hThread = (HANDLE)_beginthreadex(NULL,0, LoadThumbNail16,(LPVOID)this,0/* CREATE_SUSPENDED*/,&m_dwThreadID);
  319. m_bRunning=true;
  320. {
  321. if(m_bRunning2)return 0;
  322. CStringArray *pArray=m_pPhotopatharray;
  323. m_vFileName2.clear();
  324. for(int i=0; i<pArray->GetSize (); i++)
  325. {
  326. CString filePath=pArray->ElementAt (i);
  327. filePath.MakeLower();
  328. m_vFileName2.push_back(filePath);
  329. }
  330. TerminateThread2();
  331. m_hThread2 = (HANDLE)_beginthreadex(NULL,0, LoadThumbNail17,(LPVOID)this,0/* CREATE_SUSPENDED*/,&m_dwThreadID2);
  332. m_bRunning2=true;
  333. }
  334. SetTimer(1, 200, NULL);
  335. return TRUE; // return TRUE unless you set the focus to a control
  336. // EXCEPTION: OCX Property Pages should return FALSE
  337. }
  338. BOOL ShowEffectDlg::TerminateThread()
  339. {
  340. if ( !m_bRunning )
  341. return TRUE;
  342. m_bTerminate=true;
  343. for( ; ; )
  344. {
  345. if ( ::WaitForSingleObject(m_hThread, 0) == WAIT_OBJECT_0 )
  346. break;
  347. MSG msg;
  348. while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
  349. {
  350. if (!AfxGetApp()->PumpMessage())
  351. break;
  352. }
  353. }
  354. ::CloseHandle(m_hThread);
  355. return TRUE;
  356. }
  357. BOOL ShowEffectDlg::TerminateThread2()
  358. {
  359. if ( !m_bRunning2 )
  360. return TRUE;
  361. m_bTerminate2=true;
  362. for( ; ; )
  363. {
  364. if ( ::WaitForSingleObject(m_hThread2, 0) == WAIT_OBJECT_0 )
  365. break;
  366. MSG msg;
  367. while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
  368. {
  369. if (!AfxGetApp()->PumpMessage())
  370. break;
  371. }
  372. }
  373. ::CloseHandle(m_hThread2);
  374. return TRUE;
  375. }
  376. void ShowEffectDlg::OnDestroy()
  377. {
  378. // TODO: Add your message handler code here
  379. TerminateThread2();
  380. TerminateThread();
  381. if(m_pbmp) delete m_pbmp;m_pbmp=NULL;
  382. if(m_pImage)delete m_pImage;m_pImage=NULL;
  383. if(m_pImagebak)delete m_pImagebak;m_pImagebak=NULL;
  384. if(m_pPhoto)delete m_pPhoto;m_pPhoto=NULL;
  385. CDialog::OnDestroy();
  386. }
  387. void ShowEffectDlg::OnPaint()
  388. {
  389. CPaintDC dc(this); // device context for painting
  390. // TODO: Add your message handler code here
  391. try
  392. {
  393. if(m_pbmp)
  394. {
  395. Graphics graph2(dc.GetSafeHdc ());
  396. graph2.DrawImage(m_pbmp,110,0);
  397. }
  398. }
  399. catch(...)
  400. {
  401. }
  402. // Do not call CDialog::OnPaint() for painting messages
  403. }
  404. BOOL ShowEffectDlg::OnEraseBkgnd(CDC* pDC)
  405. {
  406. // TODO: Add your message handler code here and/or call default
  407. return 1;
  408. }
  409. void ShowEffectDlg::InitRc(Image *img)
  410. {
  411. try
  412. {
  413. if(img==NULL)return;
  414. CRect rc;
  415. GetClientRect(rc);
  416. rc.right -=220;
  417. m_rc=rc;
  418. int width,height;
  419. width=img->GetWidth();
  420. height=img->GetHeight();
  421. //////////
  422. float fscale=(float)width/(float)height;
  423. float rcscale=((float)m_rc.Width ())/((float)m_rc.Height ());
  424. int rcwid=m_rc.Width ();
  425. int rchei=m_rc.Height ();
  426. int dt=0;
  427. if(rcscale<fscale)
  428. {
  429. dt=(rchei-rcwid/fscale)/2;
  430. m_rc.top+=dt;
  431. m_rc.bottom-=dt;
  432. }
  433. else
  434. {
  435. dt=(rcwid-rchei*fscale)/2;
  436. m_rc.left +=dt;
  437. m_rc.right-=dt;
  438. }
  439. m_rcbak=m_rc;
  440. }
  441. catch(...)
  442. {
  443. }
  444. }
  445. void ShowEffectDlg::RcChange()
  446. {
  447. }
  448. int GetFileNo2()
  449. {
  450. CString path;
  451. int begin=1;
  452. path.Format ("%s\\效果图-%d.png", g_path7, begin);
  453. while (PathFileExists(path))
  454. {
  455. begin++;
  456. path.Format ("%s\\效果图-%d.png", g_path7, begin);
  457. }
  458. return begin;
  459. }
  460. extern void SaveImageToFile(Image *img, CString path);
  461. void ShowEffectDlg::OnButton1()
  462. {
  463. if(AfxMessageBox("制作方法:\r\n1.图片格式为透明PNG格式.\r\n2.显示客照的位置为透明.", MB_ICONINFORMATION));
  464. CFileDialog fdlg(true, NULL,"openfile", OFN_ALLOWMULTISELECT,"png文件(*.png)|*.png||");
  465. TCHAR szBuffer[60000]={0};
  466. fdlg.m_ofn.lpstrFile = szBuffer;
  467. fdlg.m_ofn.nMaxFile = 60000;
  468. if(fdlg.DoModal ()!=IDOK)
  469. {
  470. return;
  471. }
  472. POSITION pos=fdlg.GetStartPosition ();
  473. CStringArray array;
  474. while(pos!=NULL)
  475. {
  476. array.Add(fdlg.GetNextPathName (pos));
  477. }
  478. if(array.GetSize ()==0)return;
  479. for(int i=0; i<array.GetSize (); i++)
  480. {
  481. Bitmap *img=NULL;
  482. ::LoadImageFromBuf (&img, array.ElementAt (i));
  483. if(img==NULL)continue;
  484. if(img->GetWidth()==0)continue;
  485. if(img->GetWidth()>2000 || img->GetHeight()>2000)
  486. {
  487. CRect rc(0,0,2000,2000);
  488. RectFitDes(img->GetWidth(), img->GetHeight(), rc);
  489. Bitmap *simg=new Bitmap(rc.Width (), rc.Height (), PixelFormat32bppARGB );
  490. Graphics graphic(simg);
  491. graphic.Clear(Color(0,0,0,0));
  492. graphic.DrawImage(img, 0,0,simg->GetWidth(), simg->GetHeight() );
  493. delete img;
  494. img=simg;
  495. }
  496. CString path;
  497. CString str=array.ElementAt (i);
  498. str=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
  499. str=str.Left (str.Find ("."));
  500. /* InputName dlg;
  501. if(dlg.DoModal ()!=IDOK)
  502. {
  503. path.Format ("%s\\效果图-%d.png", g_path7, GetFileNo2());
  504. }
  505. else
  506. { */
  507. path.Format ("%s\\%s.png", g_path7, str);
  508. //}
  509. ::SaveImageToFile (img, path);
  510. str=path;
  511. CString spath=str.Left (str.ReverseFind ('\\')+1);
  512. spath+="s";
  513. spath+=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
  514. spath.Replace ("png","jpg");
  515. CRect rc(0,0,100,100);
  516. RectFitDes(img->GetWidth(), img->GetHeight(), rc);
  517. Bitmap *simg=new Bitmap(rc.Width (), rc.Height (), PixelFormat32bppARGB );
  518. Graphics graphic(simg);graphic.Clear(Color(0,0,0,0));
  519. graphic.DrawImage(img, 0,0,simg->GetWidth(), simg->GetHeight() );
  520. ::SaveImageToFile (simg, spath);
  521. delete img;delete simg;
  522. }
  523. m_effectpos=0;
  524. m_photopos=0;
  525. m_effectpatharray.RemoveAll ();
  526. using namespace helper_coffs;
  527. ffsco o;
  528. o.dirs(0);
  529. o.find(LPCSTR(g_path7), LPCSTR("*.png"));
  530. ffsco::typeT coo;
  531. ffsco::typeT::iterator it;
  532. coo = o.co_file();
  533. for (it = coo.begin(); coo.end() != it; it ++)
  534. {
  535. m_effectpatharray.Add ((*it).c_str());
  536. }
  537. if(m_effectpatharray.GetSize()==0)
  538. {
  539. AfxMessageBox("您还没有安装效果图!", MB_ICONINFORMATION);
  540. ::CreateDirectory (g_path7, NULL);
  541. }
  542. TerminateThread();
  543. CStringArray *pArray=&m_effectpatharray;
  544. m_vFileName.clear();
  545. for( i=0; i<pArray->GetSize (); i++)
  546. {
  547. CString filePath=pArray->ElementAt (i);
  548. filePath.MakeLower();
  549. m_vFileName.push_back(filePath);
  550. }
  551. m_hThread = (HANDLE)_beginthreadex(NULL,0, LoadThumbNail16,(LPVOID)this,0/* CREATE_SUSPENDED*/,&m_dwThreadID);
  552. m_bRunning=true;
  553. }
  554. void ShowEffectDlg::OnButton2()
  555. {
  556. POSITION pos;
  557. pos=m_List1.GetFirstSelectedItemPosition();
  558. if(pos==NULL)
  559. {
  560. return;
  561. }
  562. int selpos=m_List1.GetNextSelectedItem(pos);
  563. if(AfxMessageBox("确认删除吗?", MB_YESNO|MB_ICONINFORMATION)!=IDYES)return;
  564. CString str=m_effectpatharray.ElementAt (selpos);
  565. CString spath=str.Left (str.ReverseFind ('\\')+1);
  566. spath+="s";
  567. spath+=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
  568. spath.Replace ("png","jpg");
  569. ::DeleteFile(str); // 删除效果图中的jpg文件;
  570. ::DeleteFile(spath); // 删除效果图中的s的jpg文件;
  571. m_effectpatharray.RemoveAt (selpos);
  572. m_List1.DeleteItem (selpos); m_effectpos=0;
  573. m_photopos=0;
  574. }
  575. void ShowEffectDlg::OnLButtonDown(UINT nFlags, CPoint point)
  576. {
  577. // TODO: Add your message handler code here and/or call default
  578. // SetCapture();
  579. // m_startpt=point;
  580. CDialog::OnLButtonDown(nFlags, point);
  581. }
  582. void ShowEffectDlg::OnMouseMove(UINT nFlags, CPoint point)
  583. {
  584. // TODO: Add your message handler code here and/or call default
  585. /* if(GetCapture()!=this)return;
  586. if(m_rc.Width ()>m_rcscreen.Width ())
  587. {
  588. if(m_rc.left <m_rcscreen.left && point.x>m_startpt.x)
  589. {
  590. int dt=min(point.x-m_startpt.x, m_rcscreen.left-m_rc.left);
  591. m_rc.left +=dt;
  592. m_rc.right +=dt;
  593. }
  594. else if(m_rc.right >m_rcscreen.right && point.x<m_startpt.x)
  595. {
  596. int dt=min(m_startpt.x-point.x, m_rc.right-m_rcscreen.right);
  597. m_rc.left -=dt;
  598. m_rc.right -=dt;
  599. }
  600. }
  601. if(m_rc.Height ()>m_rcscreen.Height ())
  602. {
  603. if(m_rc.top <m_rcscreen.top && point.y>m_startpt.y)
  604. {
  605. int dt=min(point.y-m_startpt.y, m_rcscreen.top-m_rc.top);
  606. m_rc.top +=dt;
  607. m_rc.bottom +=dt;
  608. }
  609. else if(m_rc.bottom >m_rcscreen.bottom && point.y<m_startpt.y)
  610. {
  611. int dt=min(m_startpt.y-point.y, m_rc.bottom-m_rcscreen.bottom);
  612. m_rc.top -=dt;
  613. m_rc.bottom -=dt;
  614. }
  615. }
  616. m_startpt=point;
  617. RcChange();*/
  618. CDialog::OnMouseMove(nFlags, point);
  619. }
  620. void ShowEffectDlg::OnLButtonUp(UINT nFlags, CPoint point)
  621. {
  622. // TODO: Add your message handler code here and/or call default
  623. /* if(GetCapture()!=this)return;
  624. ReleaseCapture();*/
  625. CDialog::OnLButtonUp(nFlags, point);
  626. }
  627. BOOL ShowEffectDlg::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
  628. {
  629. // TODO: Add your message handler code here and/or call default
  630. /* if(m_pImage==NULL)return 1;
  631. if(zDelta>0)
  632. {
  633. m_fscale*=1.2;
  634. int dtx=(m_fscale*m_rcbak.Width ()-m_rc.Width ())/2.0;
  635. int dty=(m_fscale*m_rcbak.Height ()-m_rc.Height ())/2.0;
  636. m_rc.left -=dtx;
  637. m_rc.right +=dtx;
  638. m_rc.top -=dty;
  639. m_rc.bottom +=dty;
  640. }
  641. else
  642. {
  643. if(m_fscale<=1)return 1;
  644. m_fscale/=1.2;
  645. if(m_fscale<1)m_fscale=1;
  646. int dtx=(m_fscale*m_rcbak.Width ()-m_rc.Width ())/2.0;
  647. int dty=(m_fscale*m_rcbak.Height ()-m_rc.Height ())/2.0;
  648. m_rc.left -=dtx;
  649. m_rc.right +=dtx;
  650. m_rc.top -=dty;
  651. m_rc.bottom +=dty;
  652. if(m_rcbak.Height ()==m_rcscreen.Height ())
  653. {
  654. if(m_rc.top <m_rcscreen.top && m_rc.bottom < m_rcscreen.bottom )
  655. {
  656. dtx=m_rcscreen.bottom -m_rc.bottom;
  657. m_rc.top +=dtx;
  658. m_rc.bottom +=dtx;
  659. }
  660. else if(m_rc.top >m_rcscreen.top && m_rc.bottom > m_rcscreen.bottom )
  661. {
  662. dtx=m_rc.top-m_rcscreen.top;
  663. m_rc.top -=dtx;
  664. m_rc.bottom -=dtx;
  665. }
  666. dtx=m_rc.Width ();
  667. m_rc.left =(m_rcscreen.Width ()-dtx)/2;
  668. m_rc.right =m_rc.left +dtx;
  669. }
  670. if(m_rcbak.Width ()==m_rcscreen.Width ())
  671. {
  672. if(m_rc.left <m_rcscreen.left && m_rc.right < m_rcscreen.right )
  673. {
  674. dtx=m_rcscreen.right -m_rc.right;
  675. m_rc.left +=dtx;
  676. m_rc.right +=dtx;
  677. }
  678. else if(m_rc.left >m_rcscreen.left && m_rc.right > m_rcscreen.right )
  679. {
  680. dtx=m_rc.left-m_rcscreen.left;
  681. m_rc.left -=dtx;
  682. m_rc.right -=dtx;
  683. }
  684. dtx=m_rc.Height ();
  685. m_rc.top =(m_rcscreen.Height ()-dtx)/2;
  686. m_rc.bottom =m_rc.top +dtx;
  687. }
  688. }
  689. RcChange();*/
  690. return CDialog::OnMouseWheel(nFlags, zDelta, pt);
  691. }
  692. void ShowEffectDlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
  693. {
  694. // TODO: Add your control notification handler code here
  695. POSITION pos;
  696. pos=m_List1.GetFirstSelectedItemPosition();
  697. if(pos==NULL)
  698. {
  699. return;
  700. }
  701. m_effectpos=m_List1.GetNextSelectedItem(pos);m_bLoadEffect=1;
  702. MakeEffect();
  703. *pResult = 0;
  704. }
  705. void ShowEffectDlg::OnTimer(UINT nIDEvent)
  706. {
  707. // TODO: Add your message handler code here and/or call default
  708. KillTimer(nIDEvent);
  709. MakeEffect();
  710. }
  711. void ShowEffectDlg::OnClickList2(NMHDR* pNMHDR, LRESULT* pResult)
  712. {
  713. // TODO: Add your control notification handler code here
  714. POSITION pos;
  715. pos=m_List2.GetFirstSelectedItemPosition();
  716. if(pos==NULL)
  717. {
  718. return;
  719. }
  720. m_photopos=m_List2.GetNextSelectedItem(pos); m_bLoadPhoto=1;
  721. MakeEffect();
  722. *pResult = 0;
  723. }
  724. int GetLengFromPt(CPoint pt1, CPoint pt2)
  725. {
  726. return (pt1.x-pt2.x)*(pt1.x-pt2.x)+(pt1.y-pt2.y)*(pt1.y-pt2.y);
  727. }
  728. int GetLengFromPt2(CPoint pt1, CPoint pt2)
  729. {
  730. return sqrt((pt1.x-pt2.x)*(pt1.x-pt2.x)+(pt1.y-pt2.y)*(pt1.y-pt2.y));
  731. }
  732. void ShowEffectDlg::MakeEffect()
  733. {
  734. // Jeff.m_effectpatharray,客人原片\效果图\ 目录下的所有PNG图片;;
  735. if(m_effectpatharray.GetSize()==0)return;
  736. // m_pbmp:最终显示PNG效果图的Bimap对象(PNG+客人相片 合二为一的结果);
  737. Graphics graph(m_pbmp);
  738. // 将对象区域全部以透明色填充;
  739. graph.Clear(Color(255,255,255,255));
  740. if(m_bLoadPhoto)
  741. {
  742. if(m_pPhoto)delete m_pPhoto;m_pPhoto=NULL;
  743. }
  744. if(m_bLoadEffect)
  745. {
  746. if(m_pImage)delete m_pImage;m_pImage=NULL;
  747. if(m_pImagebak)delete m_pImagebak;m_pImagebak=NULL;
  748. // m_pImage为显示的PNG效果图Bitmap对象;LoadImageFromBuf指定加载哪张PNG相片作为效果图显示;
  749. ::LoadImageFromBuf(&m_pImage, m_effectpatharray.ElementAt(m_effectpos));
  750. if(m_pPhotopatharray->GetSize())
  751. GetRgn(m_pImage);
  752. m_pImagebak = m_pImage->Clone(0,0,m_pImage->GetWidth(),m_pImage->GetHeight(),PixelFormat32bppARGB );
  753. }
  754. int width,height;
  755. width=m_pImage->GetWidth();
  756. height=m_pImage->GetHeight();
  757. if(width==0 || height==0)return;
  758. InitRc(m_pImage);
  759. CPoint pt1,pt2,pt3;
  760. int leng1,leng2,leng3;
  761. CPoint curpt;
  762. int leng;
  763. Graphics graph2(m_pImage);
  764. // m_pPhotopatharray:客人的相片;
  765. if(m_pPhotopatharray->GetSize ())
  766. {
  767. if(m_bLoadPhoto)
  768. ::LoadImageFromBuf (&m_pPhoto, m_pPhotopatharray->ElementAt (m_photopos));
  769. int i;
  770. for(int aa=0; aa<RCARRARCOUNT; aa++)
  771. {
  772. leng1=leng2=leng3=10000000;
  773. for( i=0; i<m_rcarray[aa].GetSize (); i+=2)
  774. {
  775. curpt.x=m_rcarray[aa].ElementAt (i);
  776. curpt.y=m_rcarray[aa].ElementAt (i+1);
  777. leng=GetLengFromPt(CPoint(0,0), curpt);
  778. if(leng<leng1)
  779. {
  780. leng1=leng;
  781. pt1=curpt;
  782. }
  783. leng=GetLengFromPt(CPoint(m_pImage->GetWidth(),0), curpt);
  784. if(leng<leng2)
  785. {
  786. leng2=leng;
  787. pt2=curpt;
  788. }
  789. leng=GetLengFromPt(CPoint(0,m_pImage->GetHeight()), curpt);
  790. if(leng<leng3)
  791. {
  792. leng3=leng;
  793. pt3=curpt;
  794. }
  795. }
  796. if(m_rcarray[aa].GetSize ())
  797. {
  798. pt1.x*=m_tempscale;
  799. pt1.y*=m_tempscale;
  800. pt2.x*=m_tempscale;
  801. pt2.y*=m_tempscale;
  802. pt3.x*=m_tempscale;
  803. pt3.y*=m_tempscale;
  804. Point destinationPoints[] = {
  805. Point(pt1.x, pt1.y), // destination for upper-left point of original
  806. Point(pt2.x, pt2.y), // destination for upper-right point of original
  807. Point(pt3.x, pt3.y)}; // destination for lower-left point of original
  808. // graph2.DrawImage(m_pPhoto, destinationPoints, 3);
  809. int lengx=GetLengFromPt2(pt1, pt2);
  810. int lengy=GetLengFromPt2(pt1, pt3);
  811. /* CString ss;
  812. ss.Format("pt1:%d,%d pt2:%d,%d leng:%d", pt1.x, pt1.y,pt2.x, pt2.y,lengx);
  813. AfxMessageBox(ss);
  814. ss.Format("pt1:%d,%d pt3:%d,%d leng:%d", pt1.x, pt1.y,pt3.x, pt3.y,lengy);
  815. AfxMessageBox(ss);*/
  816. CRect rc(0,0,m_pPhoto->GetWidth(),m_pPhoto->GetHeight());
  817. RectFitDes(lengx,lengy,rc);
  818. graph2.DrawImage(
  819. m_pPhoto,
  820. destinationPoints,
  821. 3,
  822. rc.left,
  823. rc.top,
  824. rc.Width(),
  825. rc.Height(),
  826. UnitPixel,
  827. NULL,
  828. NULL,
  829. NULL);
  830. }
  831. }
  832. ///////
  833. graph2.DrawImage(m_pImagebak, 0, 0);
  834. }
  835. Rect destinationRect( m_rc.left , m_rc.top , m_rc.Width (), m_rc.Height () );
  836. graph.DrawImage(m_pImage, destinationRect, 0,0,width,height,UnitPixel);
  837. CRect rc;
  838. GetClientRect(rc);
  839. rc.left +=110;
  840. rc.right -=110;
  841. InvalidateRect(rc);
  842. m_bLoadEffect=0;
  843. m_bLoadPhoto=0;
  844. }
  845. // Jeff.pBmpImage2:被加载好的PNG效果相片;
  846. void ShowEffectDlg::GetRgn(Bitmap *pBmpImage2)
  847. {
  848. m_tempscale=1.0;
  849. if(pBmpImage2==NULL)return;
  850. // pBmpImage
  851. Bitmap *pBmpImage=NULL;
  852. BOOL bdelete=0;
  853. // .如果PNG效果相片长宽大于800
  854. // Bitemap::GetWidth() 获取此图像的图像高度,以像素为单位;
  855. if(pBmpImage2->GetWidth()>800 || pBmpImage2->GetHeight()>800)
  856. {
  857. bdelete=1;
  858. CRect rc(0,0,800,800);
  859. // GetWidth()的长度与CRect的长度是不一样的单位值,需要转换适合图片的比例;(一个是图片的像素尺寸,一个DC的大小尺寸)
  860. RectFitDes(pBmpImage2->GetWidth(), pBmpImage2->GetHeight(), rc);
  861. // 在适合图片长宽比例的显示设备中重新装载图片;
  862. pBmpImage=new Bitmap(rc.Width (), rc.Height (), PixelFormat32bppARGB );
  863. Graphics graphic(pBmpImage);
  864. graphic.Clear(Color(0,0,0,0));
  865. graphic.DrawImage(pBmpImage2, 0,0,pBmpImage->GetWidth(), pBmpImage->GetHeight() );
  866. m_tempscale=(float)pBmpImage2->GetWidth()/(float)pBmpImage->GetWidth();
  867. }
  868. else
  869. pBmpImage=pBmpImage2;
  870. // BitmapData这个类用于创建包含的信息来描述像素数据的位图图像的矩形区域的对象。
  871. BitmapData bitmapData;
  872. UINT* pixels;
  873. Rect rc(0, 0, pBmpImage->GetWidth(), pBmpImage->GetHeight() );
  874. // 指定格式读取pBmpImage里的图片像素到bitmapData中;
  875. pBmpImage->LockBits(
  876. rc, // 数据被加载到的区域;
  877. ImageLockModeRead, // 锁定方式:读或写;
  878. PixelFormat32bppARGB, // 数据保存的格式;
  879. &bitmapData); // 存储数据的对象;
  880. // Write to the temporary buffer provided by LockBits. RGB
  881. // Scan0:一个空指针到第一扫描线的开始
  882. pixels = (UINT*)bitmapData.Scan0;
  883. // Stride:
  884. // 一个INT值从位图区到下一个扫描线指定的字节数。这个值是负的自底向上的位图图像。
  885. DWORD wids=bitmapData.Stride/4; // 除以4,刚好为Color::alpha \red \green \blue 四色(只有PNG才有alpha色);
  886. Color color;
  887. Color color1,color2,color3,color4,color5,color6,color7,color8;
  888. // m_rcarray数组,用于记录PNG图片里的alpha色小于200的像素点坐标;
  889. BYTE R,G,B;
  890. for(int aa=0; aa<RCARRARCOUNT; aa++)
  891. m_rcarray[aa].RemoveAll(); // Jeff.清空以前的;
  892. for( INT row = 0; row < rc.Height; ++row)
  893. {
  894. for(INT col = 0; col < rc.Width-1; ++col)
  895. {
  896. // 将第一行取4个点填充color对象;
  897. color.SetValue(pixels[row * wids + col]);
  898. // Color::GetA() 方法获取此Color对象的alpha分量(返回这个颜色的alpha分量)。
  899. if(color.GetA() < 200)
  900. {
  901. CArray<int,int>*pArray=NULL;
  902. for(int aa=0; aa<RCARRARCOUNT; aa++)
  903. {
  904. if(m_rcarray[aa].GetSize() && pArray==NULL)
  905. {
  906. double x=m_rcarray[aa].ElementAt(0);
  907. double y=m_rcarray[aa].ElementAt(1);
  908. int x0=(int)x;
  909. int y0=(int)y;
  910. double dtx=col-x;
  911. double dty=row-y;
  912. if(abs(dtx)>abs(dty))
  913. {
  914. if(dty)
  915. {
  916. dtx/=abs(dty);
  917. dty/=abs(dty);
  918. }
  919. else if(dtx>0)
  920. dtx=1;
  921. else if(dtx<0)
  922. dtx=-1;
  923. }
  924. else
  925. {
  926. if(dtx)
  927. {
  928. dty/=abs(dtx);
  929. dtx/=abs(dtx);
  930. }
  931. else if(dty>0)
  932. dty=1;
  933. else if(dtx<0)
  934. dty=-1;
  935. }
  936. if(dtx>3)
  937. {
  938. double step=dtx/3.0;
  939. dtx/=step;
  940. dty/=step;
  941. }
  942. if(dty>3)
  943. {
  944. double step=dty/3.0;
  945. dtx/=step;
  946. dty/=step;
  947. }
  948. BOOL bFind=0;
  949. while(1)
  950. {
  951. x+=dtx;
  952. y+=dty;
  953. if(x>=(rc.Width-1) || x<1)break;
  954. if(y>=(rc.Height-1) || y<1)break;
  955. if(col>x0)
  956. {
  957. if(x<x0)
  958. {
  959. break;
  960. }
  961. if(x>col)
  962. {
  963. break;
  964. }
  965. }
  966. if(col<x0)
  967. {
  968. if(x>x0)
  969. {
  970. break;
  971. }
  972. if(x<col)
  973. {
  974. break;
  975. }
  976. }
  977. if(row>y0)
  978. {
  979. if(y<y0)
  980. {
  981. break;
  982. }
  983. if(y>row)
  984. {
  985. break;
  986. }
  987. }
  988. if(row<y0)
  989. {
  990. if(y>y0)
  991. {
  992. break;
  993. }
  994. if(y<row)
  995. {
  996. break;
  997. }
  998. }
  999. color.SetValue(pixels[(int)y * wids + (int)x]);
  1000. if(color.GetA()==255)
  1001. {
  1002. color1.SetValue(pixels[(int)(y-1) * wids + (int)(x-1)]);
  1003. color2.SetValue(pixels[(int)(y-1) * wids + (int)(x-0)]);
  1004. color3.SetValue(pixels[(int)(y-1) * wids + (int)(x+1)]);
  1005. color4.SetValue(pixels[(int)(y-0) * wids + (int)(x-1)]);
  1006. color5.SetValue(pixels[(int)(y-0) * wids + (int)(x+1)]);
  1007. color6.SetValue(pixels[(int)(y+1) * wids + (int)(x-1)]);
  1008. color7.SetValue(pixels[(int)(y+1) * wids + (int)(x-0)]);
  1009. color8.SetValue(pixels[(int)(y+1) * wids + (int)(x+1)]);
  1010. if(color1.GetA()==255 && color2.GetA()==255 && color3.GetA()==255 && color4.GetA()==255 && color5.GetA()==255 && color6.GetA()==255 && color7.GetA()==255 && color8.GetA()==255)
  1011. {
  1012. bFind=1;
  1013. break;
  1014. }
  1015. }
  1016. }
  1017. if(bFind==0)
  1018. pArray=&(m_rcarray[aa]);
  1019. }
  1020. }
  1021. if(pArray==NULL)
  1022. {
  1023. BOOL bcontinue=1;
  1024. for(int yy=0; yy<RCARRARCOUNT; yy++)
  1025. {
  1026. if(m_rcarray[yy].GetSize()==0)
  1027. {
  1028. pArray=&(m_rcarray[yy]);
  1029. bcontinue=0;
  1030. break;
  1031. }
  1032. }
  1033. if(bcontinue)continue;
  1034. }
  1035. pArray->Add(col); // x坐标;
  1036. pArray->Add(row); // y坐标;
  1037. }
  1038. }
  1039. }
  1040. pBmpImage->UnlockBits(&bitmapData);
  1041. if(bdelete)delete pBmpImage;
  1042. /*
  1043. if(pBmpImage==NULL)return;
  1044. BitmapData bitmapData;
  1045. UINT* pixels;
  1046. Rect rc(0, 0, pBmpImage->GetWidth(), pBmpImage->GetHeight() );
  1047. pBmpImage->LockBits(
  1048. rc,
  1049. ImageLockModeRead,
  1050. PixelFormat32bppARGB,
  1051. &bitmapData);
  1052. // Write to the temporary buffer provided by LockBits. RGB
  1053. pixels = (UINT*)bitmapData.Scan0;
  1054. DWORD wids=bitmapData.Stride/4;
  1055. Color color;
  1056. Color color1,color2,color3,color4,color5,color6,color7,color8;
  1057. BYTE R,G,B;
  1058. m_rcarray1.RemoveAll ();
  1059. m_rcarray2.RemoveAll ();
  1060. m_rcarray3.RemoveAll ();
  1061. m_rcarray4.RemoveAll ();
  1062. m_rcarray5.RemoveAll ();
  1063. for( INT row = 0; row < rc.Height; ++row)
  1064. {
  1065. for(INT col = 0; col < rc.Width-1; ++col)
  1066. {
  1067. color.SetValue(pixels[row * wids + col]);
  1068. if(color.GetA()<200)
  1069. {
  1070. CArray<int,int>*pArray=NULL;
  1071. if(m_rcarray1.GetSize () && pArray==NULL)
  1072. {
  1073. double x=m_rcarray1.ElementAt (0);
  1074. double y=m_rcarray1.ElementAt (1);
  1075. double dtx=col-x;
  1076. double dty=row-y;
  1077. dtx/=10.0;dty/=10.0;
  1078. BOOL bFind=0;
  1079. for(int a=0; a<10; a++)
  1080. {
  1081. x+=dtx;
  1082. y+=dty;
  1083. color.SetValue(pixels[(int)y * wids + (int)x]);
  1084. if(color.GetA()==255)
  1085. {
  1086. color1.SetValue(pixels[(int)(y-1) * wids + (int)(x-1)]);
  1087. color2.SetValue(pixels[(int)(y-1) * wids + (int)(x-0)]);
  1088. color3.SetValue(pixels[(int)(y-1) * wids + (int)(x+1)]);
  1089. color4.SetValue(pixels[(int)(y-0) * wids + (int)(x-1)]);
  1090. color5.SetValue(pixels[(int)(y-0) * wids + (int)(x+1)]);
  1091. color6.SetValue(pixels[(int)(y+1) * wids + (int)(x-1)]);
  1092. color7.SetValue(pixels[(int)(y+1) * wids + (int)(x-0)]);
  1093. color8.SetValue(pixels[(int)(y+1) * wids + (int)(x+1)]);
  1094. if(color1.GetA()==255 && color2.GetA()==255 && color3.GetA()==255 && color4.GetA()==255 && color5.GetA()==255 && color6.GetA()==255 && color7.GetA()==255 && color8.GetA()==255)
  1095. {
  1096. bFind=1;
  1097. break;
  1098. }
  1099. }
  1100. }
  1101. if(bFind==0)pArray=&m_rcarray1;
  1102. }
  1103. if(m_rcarray2.GetSize () && pArray==NULL)
  1104. {
  1105. double x=m_rcarray2.ElementAt (0);
  1106. double y=m_rcarray2.ElementAt (1);
  1107. double dtx=col-x;dtx/=10.0;
  1108. double dty=row-y;dty/=10.0;
  1109. BOOL bFind=0;
  1110. for(int a=0; a<10; a++)
  1111. {
  1112. x+=dtx;
  1113. y+=dty;
  1114. color.SetValue(pixels[(int)y * wids + (int)x]);
  1115. if(color.GetA()==255)
  1116. {
  1117. color1.SetValue(pixels[(int)(y-1) * wids + (int)(x-1)]);
  1118. color2.SetValue(pixels[(int)(y-1) * wids + (int)(x-0)]);
  1119. color3.SetValue(pixels[(int)(y-1) * wids + (int)(x+1)]);
  1120. color4.SetValue(pixels[(int)(y-0) * wids + (int)(x-1)]);
  1121. color5.SetValue(pixels[(int)(y-0) * wids + (int)(x+1)]);
  1122. color6.SetValue(pixels[(int)(y+1) * wids + (int)(x-1)]);
  1123. color7.SetValue(pixels[(int)(y+1) * wids + (int)(x-0)]);
  1124. color8.SetValue(pixels[(int)(y+1) * wids + (int)(x+1)]);
  1125. if(color1.GetA()==255 && color2.GetA()==255 && color3.GetA()==255 && color4.GetA()==255 && color5.GetA()==255 && color6.GetA()==255 && color7.GetA()==255 && color8.GetA()==255)
  1126. {
  1127. bFind=1;
  1128. break;
  1129. }
  1130. }
  1131. }
  1132. if(bFind==0)pArray=&m_rcarray2;
  1133. }
  1134. if(m_rcarray3.GetSize () && pArray==NULL)
  1135. {
  1136. double x=m_rcarray3.ElementAt (0);
  1137. double y=m_rcarray3.ElementAt (1);
  1138. double dtx=col-x;dtx/=10.0;
  1139. double dty=row-y;dty/=10.0;
  1140. BOOL bFind=0;
  1141. for(int a=0; a<10; a++)
  1142. {
  1143. x+=dtx;
  1144. y+=dty;
  1145. color.SetValue(pixels[(int)y * wids + (int)x]);
  1146. if(color.GetA()==255)
  1147. {
  1148. color1.SetValue(pixels[(int)(y-1) * wids + (int)(x-1)]);
  1149. color2.SetValue(pixels[(int)(y-1) * wids + (int)(x-0)]);
  1150. color3.SetValue(pixels[(int)(y-1) * wids + (int)(x+1)]);
  1151. color4.SetValue(pixels[(int)(y-0) * wids + (int)(x-1)]);
  1152. color5.SetValue(pixels[(int)(y-0) * wids + (int)(x+1)]);
  1153. color6.SetValue(pixels[(int)(y+1) * wids + (int)(x-1)]);
  1154. color7.SetValue(pixels[(int)(y+1) * wids + (int)(x-0)]);
  1155. color8.SetValue(pixels[(int)(y+1) * wids + (int)(x+1)]);
  1156. if(color1.GetA()==255 && color2.GetA()==255 && color3.GetA()==255 && color4.GetA()==255 && color5.GetA()==255 && color6.GetA()==255 && color7.GetA()==255 && color8.GetA()==255)
  1157. {
  1158. bFind=1;
  1159. break;
  1160. }
  1161. }
  1162. }
  1163. if(bFind==0)pArray=&m_rcarray3;
  1164. }
  1165. if(m_rcarray4.GetSize () && pArray==NULL)
  1166. {
  1167. double x=m_rcarray4.ElementAt (0);
  1168. double y=m_rcarray4.ElementAt (1);
  1169. double dtx=col-x;dtx/=10.0;
  1170. double dty=row-y;dty/=10.0;
  1171. BOOL bFind=0;
  1172. for(int a=0; a<10; a++)
  1173. {
  1174. x+=dtx;
  1175. y+=dty;
  1176. color.SetValue(pixels[(int)y * wids + (int)x]);
  1177. if(color.GetA()==255)
  1178. {
  1179. color1.SetValue(pixels[(int)(y-1) * wids + (int)(x-1)]);
  1180. color2.SetValue(pixels[(int)(y-1) * wids + (int)(x-0)]);
  1181. color3.SetValue(pixels[(int)(y-1) * wids + (int)(x+1)]);
  1182. color4.SetValue(pixels[(int)(y-0) * wids + (int)(x-1)]);
  1183. color5.SetValue(pixels[(int)(y-0) * wids + (int)(x+1)]);
  1184. color6.SetValue(pixels[(int)(y+1) * wids + (int)(x-1)]);
  1185. color7.SetValue(pixels[(int)(y+1) * wids + (int)(x-0)]);
  1186. color8.SetValue(pixels[(int)(y+1) * wids + (int)(x+1)]);
  1187. if(color1.GetA()==255 && color2.GetA()==255 && color3.GetA()==255 && color4.GetA()==255 && color5.GetA()==255 && color6.GetA()==255 && color7.GetA()==255 && color8.GetA()==255)
  1188. {
  1189. bFind=1;
  1190. break;
  1191. }
  1192. }
  1193. }
  1194. if(bFind==0)pArray=&m_rcarray4;
  1195. }
  1196. if(m_rcarray5.GetSize () && pArray==NULL)
  1197. {
  1198. double x=m_rcarray5.ElementAt (0);
  1199. double y=m_rcarray5.ElementAt (1);
  1200. double dtx=col-x;dtx/=10.0;
  1201. double dty=row-y;dty/=10.0;
  1202. BOOL bFind=0;
  1203. for(int a=0; a<10; a++)
  1204. {
  1205. x+=dtx;
  1206. y+=dty;
  1207. color.SetValue(pixels[(int)y * wids + (int)x]);
  1208. if(color.GetA()==255)
  1209. {
  1210. color1.SetValue(pixels[(int)(y-1) * wids + (int)(x-1)]);
  1211. color2.SetValue(pixels[(int)(y-1) * wids + (int)(x-0)]);
  1212. color3.SetValue(pixels[(int)(y-1) * wids + (int)(x+1)]);
  1213. color4.SetValue(pixels[(int)(y-0) * wids + (int)(x-1)]);
  1214. color5.SetValue(pixels[(int)(y-0) * wids + (int)(x+1)]);
  1215. color6.SetValue(pixels[(int)(y+1) * wids + (int)(x-1)]);
  1216. color7.SetValue(pixels[(int)(y+1) * wids + (int)(x-0)]);
  1217. color8.SetValue(pixels[(int)(y+1) * wids + (int)(x+1)]);
  1218. if(color1.GetA()==255 && color2.GetA()==255 && color3.GetA()==255 && color4.GetA()==255 && color5.GetA()==255 && color6.GetA()==255 && color7.GetA()==255 && color8.GetA()==255)
  1219. {
  1220. bFind=1;
  1221. break;
  1222. }
  1223. }
  1224. }
  1225. if(bFind==0)pArray=&m_rcarray5;
  1226. }
  1227. if(pArray==NULL)
  1228. {
  1229. if(m_rcarray1.GetSize ()==0)
  1230. pArray=&m_rcarray1;
  1231. else if(m_rcarray2.GetSize ()==0)
  1232. pArray=&m_rcarray2;
  1233. else if(m_rcarray3.GetSize ()==0)
  1234. pArray=&m_rcarray3;
  1235. else if(m_rcarray4.GetSize ()==0)
  1236. pArray=&m_rcarray4;
  1237. else if(m_rcarray5.GetSize ()==0)
  1238. pArray=&m_rcarray5;
  1239. else continue;
  1240. }
  1241. pArray->Add (col);pArray->Add (row);
  1242. }
  1243. }
  1244. }
  1245. pBmpImage->UnlockBits(&bitmapData);
  1246. */
  1247. }