ShowEffect.cpp 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424
  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. int i = 0;
  464. if(AfxMessageBox("制作方法:\r\n1.图片格式为透明PNG格式.\r\n2.显示客照的位置为透明.", MB_ICONINFORMATION));
  465. CFileDialog fdlg(true, NULL,"openfile", OFN_ALLOWMULTISELECT,"png文件(*.png)|*.png||");
  466. TCHAR szBuffer[60000]={0};
  467. fdlg.m_ofn.lpstrFile = szBuffer;
  468. fdlg.m_ofn.nMaxFile = 60000;
  469. if(fdlg.DoModal ()!=IDOK)
  470. {
  471. return;
  472. }
  473. POSITION pos=fdlg.GetStartPosition ();
  474. CStringArray array;
  475. while(pos!=NULL)
  476. {
  477. array.Add(fdlg.GetNextPathName (pos));
  478. }
  479. if(array.GetSize ()==0)return;
  480. for( i=0; i<array.GetSize (); i++)
  481. {
  482. Bitmap *img=NULL;
  483. ::LoadImageFromBuf (&img, array.ElementAt (i));
  484. if(img==NULL)continue;
  485. if(img->GetWidth()==0)continue;
  486. if(img->GetWidth()>2000 || img->GetHeight()>2000)
  487. {
  488. CRect rc(0,0,2000,2000);
  489. RectFitDes(img->GetWidth(), img->GetHeight(), rc);
  490. Bitmap *simg=new Bitmap(rc.Width (), rc.Height (), PixelFormat32bppARGB );
  491. Graphics graphic(simg);
  492. graphic.Clear(Color(0,0,0,0));
  493. graphic.DrawImage(img, 0,0,simg->GetWidth(), simg->GetHeight() );
  494. delete img;
  495. img=simg;
  496. }
  497. CString path;
  498. CString str=array.ElementAt (i);
  499. str=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
  500. str=str.Left (str.Find ("."));
  501. /* InputName dlg;
  502. if(dlg.DoModal ()!=IDOK)
  503. {
  504. path.Format ("%s\\效果图-%d.png", g_path7, GetFileNo2());
  505. }
  506. else
  507. { */
  508. path.Format ("%s\\%s.png", g_path7, str);
  509. //}
  510. ::SaveImageToFile (img, path);
  511. str=path;
  512. CString spath=str.Left (str.ReverseFind ('\\')+1);
  513. spath+="s";
  514. spath+=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
  515. spath.Replace ("png","jpg");
  516. CRect rc(0,0,100,100);
  517. RectFitDes(img->GetWidth(), img->GetHeight(), rc);
  518. Bitmap *simg=new Bitmap(rc.Width (), rc.Height (), PixelFormat32bppARGB );
  519. Graphics graphic(simg);graphic.Clear(Color(0,0,0,0));
  520. graphic.DrawImage(img, 0,0,simg->GetWidth(), simg->GetHeight() );
  521. ::SaveImageToFile (simg, spath);
  522. delete img;delete simg;
  523. }
  524. m_effectpos=0;
  525. m_photopos=0;
  526. m_effectpatharray.RemoveAll ();
  527. using namespace helper_coffs;
  528. ffsco o;
  529. o.dirs(0);
  530. o.find(LPCSTR(g_path7), LPCSTR("*.png"));
  531. ffsco::typeT coo;
  532. ffsco::typeT::iterator it;
  533. coo = o.co_file();
  534. for (it = coo.begin(); coo.end() != it; it ++)
  535. {
  536. m_effectpatharray.Add ((*it).c_str());
  537. }
  538. if(m_effectpatharray.GetSize()==0)
  539. {
  540. AfxMessageBox("您还没有安装效果图!", MB_ICONINFORMATION);
  541. ::CreateDirectory (g_path7, NULL);
  542. }
  543. TerminateThread();
  544. CStringArray *pArray=&m_effectpatharray;
  545. m_vFileName.clear();
  546. for( i=0; i<pArray->GetSize (); i++)
  547. {
  548. CString filePath=pArray->ElementAt (i);
  549. filePath.MakeLower();
  550. m_vFileName.push_back(filePath);
  551. }
  552. m_hThread = (HANDLE)_beginthreadex(NULL,0, LoadThumbNail16,(LPVOID)this,0/* CREATE_SUSPENDED*/,&m_dwThreadID);
  553. m_bRunning=true;
  554. }
  555. void ShowEffectDlg::OnButton2()
  556. {
  557. POSITION pos;
  558. pos=m_List1.GetFirstSelectedItemPosition();
  559. if(pos==NULL)
  560. {
  561. return;
  562. }
  563. int selpos=m_List1.GetNextSelectedItem(pos);
  564. if(AfxMessageBox("确认删除吗?", MB_YESNO|MB_ICONINFORMATION)!=IDYES)return;
  565. CString str=m_effectpatharray.ElementAt (selpos);
  566. CString spath=str.Left (str.ReverseFind ('\\')+1);
  567. spath+="s";
  568. spath+=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
  569. spath.Replace ("png","jpg");
  570. ::DeleteFile (str);
  571. ::DeleteFile(spath);
  572. m_effectpatharray.RemoveAt (selpos);
  573. m_List1.DeleteItem (selpos); m_effectpos=0;
  574. m_photopos=0;
  575. }
  576. void ShowEffectDlg::OnLButtonDown(UINT nFlags, CPoint point)
  577. {
  578. // TODO: Add your message handler code here and/or call default
  579. // SetCapture();
  580. // m_startpt=point;
  581. CDialog::OnLButtonDown(nFlags, point);
  582. }
  583. void ShowEffectDlg::OnMouseMove(UINT nFlags, CPoint point)
  584. {
  585. // TODO: Add your message handler code here and/or call default
  586. /* if(GetCapture()!=this)return;
  587. if(m_rc.Width ()>m_rcscreen.Width ())
  588. {
  589. if(m_rc.left <m_rcscreen.left && point.x>m_startpt.x)
  590. {
  591. int dt=min(point.x-m_startpt.x, m_rcscreen.left-m_rc.left);
  592. m_rc.left +=dt;
  593. m_rc.right +=dt;
  594. }
  595. else if(m_rc.right >m_rcscreen.right && point.x<m_startpt.x)
  596. {
  597. int dt=min(m_startpt.x-point.x, m_rc.right-m_rcscreen.right);
  598. m_rc.left -=dt;
  599. m_rc.right -=dt;
  600. }
  601. }
  602. if(m_rc.Height ()>m_rcscreen.Height ())
  603. {
  604. if(m_rc.top <m_rcscreen.top && point.y>m_startpt.y)
  605. {
  606. int dt=min(point.y-m_startpt.y, m_rcscreen.top-m_rc.top);
  607. m_rc.top +=dt;
  608. m_rc.bottom +=dt;
  609. }
  610. else if(m_rc.bottom >m_rcscreen.bottom && point.y<m_startpt.y)
  611. {
  612. int dt=min(m_startpt.y-point.y, m_rc.bottom-m_rcscreen.bottom);
  613. m_rc.top -=dt;
  614. m_rc.bottom -=dt;
  615. }
  616. }
  617. m_startpt=point;
  618. RcChange();*/
  619. CDialog::OnMouseMove(nFlags, point);
  620. }
  621. void ShowEffectDlg::OnLButtonUp(UINT nFlags, CPoint point)
  622. {
  623. // TODO: Add your message handler code here and/or call default
  624. /* if(GetCapture()!=this)return;
  625. ReleaseCapture();*/
  626. CDialog::OnLButtonUp(nFlags, point);
  627. }
  628. BOOL ShowEffectDlg::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
  629. {
  630. // TODO: Add your message handler code here and/or call default
  631. /* if(m_pImage==NULL)return 1;
  632. if(zDelta>0)
  633. {
  634. m_fscale*=1.2;
  635. int dtx=(m_fscale*m_rcbak.Width ()-m_rc.Width ())/2.0;
  636. int dty=(m_fscale*m_rcbak.Height ()-m_rc.Height ())/2.0;
  637. m_rc.left -=dtx;
  638. m_rc.right +=dtx;
  639. m_rc.top -=dty;
  640. m_rc.bottom +=dty;
  641. }
  642. else
  643. {
  644. if(m_fscale<=1)return 1;
  645. m_fscale/=1.2;
  646. if(m_fscale<1)m_fscale=1;
  647. int dtx=(m_fscale*m_rcbak.Width ()-m_rc.Width ())/2.0;
  648. int dty=(m_fscale*m_rcbak.Height ()-m_rc.Height ())/2.0;
  649. m_rc.left -=dtx;
  650. m_rc.right +=dtx;
  651. m_rc.top -=dty;
  652. m_rc.bottom +=dty;
  653. if(m_rcbak.Height ()==m_rcscreen.Height ())
  654. {
  655. if(m_rc.top <m_rcscreen.top && m_rc.bottom < m_rcscreen.bottom )
  656. {
  657. dtx=m_rcscreen.bottom -m_rc.bottom;
  658. m_rc.top +=dtx;
  659. m_rc.bottom +=dtx;
  660. }
  661. else if(m_rc.top >m_rcscreen.top && m_rc.bottom > m_rcscreen.bottom )
  662. {
  663. dtx=m_rc.top-m_rcscreen.top;
  664. m_rc.top -=dtx;
  665. m_rc.bottom -=dtx;
  666. }
  667. dtx=m_rc.Width ();
  668. m_rc.left =(m_rcscreen.Width ()-dtx)/2;
  669. m_rc.right =m_rc.left +dtx;
  670. }
  671. if(m_rcbak.Width ()==m_rcscreen.Width ())
  672. {
  673. if(m_rc.left <m_rcscreen.left && m_rc.right < m_rcscreen.right )
  674. {
  675. dtx=m_rcscreen.right -m_rc.right;
  676. m_rc.left +=dtx;
  677. m_rc.right +=dtx;
  678. }
  679. else if(m_rc.left >m_rcscreen.left && m_rc.right > m_rcscreen.right )
  680. {
  681. dtx=m_rc.left-m_rcscreen.left;
  682. m_rc.left -=dtx;
  683. m_rc.right -=dtx;
  684. }
  685. dtx=m_rc.Height ();
  686. m_rc.top =(m_rcscreen.Height ()-dtx)/2;
  687. m_rc.bottom =m_rc.top +dtx;
  688. }
  689. }
  690. RcChange();*/
  691. return CDialog::OnMouseWheel(nFlags, zDelta, pt);
  692. }
  693. void ShowEffectDlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
  694. {
  695. // TODO: Add your control notification handler code here
  696. POSITION pos;
  697. pos=m_List1.GetFirstSelectedItemPosition();
  698. if(pos==NULL)
  699. {
  700. return;
  701. }
  702. m_effectpos=m_List1.GetNextSelectedItem(pos);m_bLoadEffect=1;
  703. MakeEffect();
  704. *pResult = 0;
  705. }
  706. void ShowEffectDlg::OnTimer(UINT nIDEvent)
  707. {
  708. // TODO: Add your message handler code here and/or call default
  709. KillTimer(nIDEvent);
  710. MakeEffect();
  711. }
  712. void ShowEffectDlg::OnClickList2(NMHDR* pNMHDR, LRESULT* pResult)
  713. {
  714. // TODO: Add your control notification handler code here
  715. POSITION pos;
  716. pos=m_List2.GetFirstSelectedItemPosition();
  717. if(pos==NULL)
  718. {
  719. return;
  720. }
  721. m_photopos=m_List2.GetNextSelectedItem(pos); m_bLoadPhoto=1;
  722. MakeEffect();
  723. *pResult = 0;
  724. }
  725. int GetLengFromPt(CPoint pt1, CPoint pt2)
  726. {
  727. return (pt1.x-pt2.x)*(pt1.x-pt2.x)+(pt1.y-pt2.y)*(pt1.y-pt2.y);
  728. }
  729. int GetLengFromPt2(CPoint pt1, CPoint pt2)
  730. {
  731. return sqrt((double)(pt1.x-pt2.x)*(pt1.x-pt2.x)+(pt1.y-pt2.y)*(pt1.y-pt2.y));
  732. }
  733. void ShowEffectDlg::MakeEffect()
  734. {
  735. // Jeff.m_effectpatharray,客人原片\效果图\ 目录下的所有PNG图片;;
  736. if(m_effectpatharray.GetSize()==0)return;
  737. // m_pbmp:最终显示PNG效果图的Bimap对象(PNG+客人相片 合二为一的结果);
  738. Graphics graph(m_pbmp);
  739. // 将对象区域全部以透明色填充;
  740. graph.Clear(Color(255,255,255,255));
  741. if(m_bLoadPhoto)
  742. {
  743. if(m_pPhoto)delete m_pPhoto;m_pPhoto=NULL;
  744. }
  745. if(m_bLoadEffect)
  746. {
  747. if(m_pImage)delete m_pImage;m_pImage=NULL;
  748. if(m_pImagebak)delete m_pImagebak;m_pImagebak=NULL;
  749. // m_pImage为显示的PNG效果图Bitmap对象;LoadImageFromBuf指定加载哪张PNG相片作为效果图显示;
  750. ::LoadImageFromBuf(&m_pImage, m_effectpatharray.ElementAt(m_effectpos));
  751. if(m_pPhotopatharray->GetSize())
  752. GetRgn(m_pImage);
  753. m_pImagebak = m_pImage->Clone(0,0,m_pImage->GetWidth(),m_pImage->GetHeight(),PixelFormat32bppARGB );
  754. }
  755. int width,height;
  756. width=m_pImage->GetWidth();
  757. height=m_pImage->GetHeight();
  758. if(width==0 || height==0)return;
  759. InitRc(m_pImage);
  760. CPoint pt1,pt2,pt3;
  761. int leng1,leng2,leng3;
  762. CPoint curpt;
  763. int leng;
  764. Graphics graph2(m_pImage);
  765. // m_pPhotopatharray:客人的相片;
  766. if(m_pPhotopatharray->GetSize ())
  767. {
  768. if(m_bLoadPhoto)
  769. ::LoadImageFromBuf (&m_pPhoto, m_pPhotopatharray->ElementAt (m_photopos));
  770. int i;
  771. for(int aa=0; aa<RCARRARCOUNT; aa++)
  772. {
  773. leng1=leng2=leng3=10000000;
  774. for( i=0; i<m_rcarray[aa].GetSize (); i+=2)
  775. {
  776. curpt.x=m_rcarray[aa].ElementAt (i);
  777. curpt.y=m_rcarray[aa].ElementAt (i+1);
  778. leng=GetLengFromPt(CPoint(0,0), curpt);
  779. if(leng<leng1)
  780. {
  781. leng1=leng;
  782. pt1=curpt;
  783. }
  784. leng=GetLengFromPt(CPoint(m_pImage->GetWidth(),0), curpt);
  785. if(leng<leng2)
  786. {
  787. leng2=leng;
  788. pt2=curpt;
  789. }
  790. leng=GetLengFromPt(CPoint(0,m_pImage->GetHeight()), curpt);
  791. if(leng<leng3)
  792. {
  793. leng3=leng;
  794. pt3=curpt;
  795. }
  796. }
  797. if(m_rcarray[aa].GetSize ())
  798. {
  799. pt1.x*=m_tempscale;
  800. pt1.y*=m_tempscale;
  801. pt2.x*=m_tempscale;
  802. pt2.y*=m_tempscale;
  803. pt3.x*=m_tempscale;
  804. pt3.y*=m_tempscale;
  805. Point destinationPoints[] = {
  806. Point(pt1.x, pt1.y), // destination for upper-left point of original
  807. Point(pt2.x, pt2.y), // destination for upper-right point of original
  808. Point(pt3.x, pt3.y)}; // destination for lower-left point of original
  809. // graph2.DrawImage(m_pPhoto, destinationPoints, 3);
  810. int lengx=GetLengFromPt2(pt1, pt2);
  811. int lengy=GetLengFromPt2(pt1, pt3);
  812. /* CString ss;
  813. ss.Format("pt1:%d,%d pt2:%d,%d leng:%d", pt1.x, pt1.y,pt2.x, pt2.y,lengx);
  814. AfxMessageBox(ss);
  815. ss.Format("pt1:%d,%d pt3:%d,%d leng:%d", pt1.x, pt1.y,pt3.x, pt3.y,lengy);
  816. AfxMessageBox(ss);*/
  817. CRect rc(0,0,m_pPhoto->GetWidth(),m_pPhoto->GetHeight());
  818. RectFitDes(lengx,lengy,rc);
  819. graph2.DrawImage(
  820. m_pPhoto,
  821. destinationPoints,
  822. 3,
  823. rc.left,
  824. rc.top,
  825. rc.Width(),
  826. rc.Height(),
  827. UnitPixel,
  828. NULL,
  829. NULL,
  830. NULL);
  831. }
  832. }
  833. ///////
  834. graph2.DrawImage(m_pImagebak, 0, 0);
  835. }
  836. Rect destinationRect( m_rc.left , m_rc.top , m_rc.Width (), m_rc.Height () );
  837. graph.DrawImage(m_pImage, destinationRect, 0,0,width,height,UnitPixel);
  838. CRect rc;
  839. GetClientRect(rc);
  840. rc.left +=110;
  841. rc.right -=110;
  842. InvalidateRect(rc);
  843. m_bLoadEffect=0;
  844. m_bLoadPhoto=0;
  845. }
  846. // Jeff.pBmpImage2:被加载好的PNG效果相片;
  847. void ShowEffectDlg::GetRgn(Bitmap *pBmpImage2)
  848. {
  849. m_tempscale=1.0;
  850. if(pBmpImage2==NULL)return;
  851. // pBmpImage
  852. Bitmap *pBmpImage=NULL;
  853. BOOL bdelete=0;
  854. // .如果PNG效果相片长宽大于800
  855. // Bitemap::GetWidth() 获取此图像的图像高度,以像素为单位;
  856. if(pBmpImage2->GetWidth()>800 || pBmpImage2->GetHeight()>800)
  857. {
  858. bdelete=1;
  859. CRect rc(0,0,800,800);
  860. // GetWidth()的长度与CRect的长度是不一样的单位值,需要转换适合图片的比例;(一个是图片的像素尺寸,一个DC的大小尺寸)
  861. RectFitDes(pBmpImage2->GetWidth(), pBmpImage2->GetHeight(), rc);
  862. // 在适合图片长宽比例的显示设备中重新装载图片;
  863. pBmpImage=new Bitmap(rc.Width (), rc.Height (), PixelFormat32bppARGB );
  864. Graphics graphic(pBmpImage);
  865. graphic.Clear(Color(0,0,0,0));
  866. graphic.DrawImage(pBmpImage2, 0,0,pBmpImage->GetWidth(), pBmpImage->GetHeight() );
  867. m_tempscale=(float)pBmpImage2->GetWidth()/(float)pBmpImage->GetWidth();
  868. }
  869. else
  870. pBmpImage=pBmpImage2;
  871. // BitmapData这个类用于创建包含的信息来描述像素数据的位图图像的矩形区域的对象。
  872. BitmapData bitmapData;
  873. UINT* pixels;
  874. Rect rc(0, 0, pBmpImage->GetWidth(), pBmpImage->GetHeight() );
  875. // 指定格式读取pBmpImage里的图片像素到bitmapData中;
  876. pBmpImage->LockBits(
  877. rc, // 数据被加载到的区域;
  878. ImageLockModeRead, // 锁定方式:读或写;
  879. PixelFormat32bppARGB, // 数据保存的格式;
  880. &bitmapData); // 存储数据的对象;
  881. // Write to the temporary buffer provided by LockBits. RGB
  882. // Scan0:一个空指针到第一扫描线的开始
  883. pixels = (UINT*)bitmapData.Scan0;
  884. // Stride:
  885. // 一个INT值从位图区到下一个扫描线指定的字节数。这个值是负的自底向上的位图图像。
  886. DWORD wids=bitmapData.Stride/4; // 除以4,刚好为Color::alpha \red \green \blue 四色(只有PNG才有alpha色);
  887. Color color;
  888. Color color1,color2,color3,color4,color5,color6,color7,color8;
  889. // m_rcarray数组,用于记录PNG图片里的alpha色小于200的像素点坐标;
  890. BYTE R,G,B;
  891. for(int aa=0; aa<RCARRARCOUNT; aa++)
  892. m_rcarray[aa].RemoveAll(); // Jeff.清空以前的;
  893. for( INT row = 0; row < rc.Height; ++row)
  894. {
  895. for(INT col = 0; col < rc.Width-1; ++col)
  896. {
  897. // 将第一行取4个点填充color对象;
  898. color.SetValue(pixels[row * wids + col]);
  899. // Color::GetA() 方法获取此Color对象的alpha分量(返回这个颜色的alpha分量)。
  900. if(color.GetA() < 200)
  901. {
  902. CArray<int,int>*pArray=NULL;
  903. for(int aa=0; aa<RCARRARCOUNT; aa++)
  904. {
  905. if(m_rcarray[aa].GetSize() && pArray==NULL)
  906. {
  907. double x=m_rcarray[aa].ElementAt(0);
  908. double y=m_rcarray[aa].ElementAt(1);
  909. int x0=(int)x;
  910. int y0=(int)y;
  911. double dtx=col-x;
  912. double dty=row-y;
  913. if(abs(dtx)>abs(dty))
  914. {
  915. if(dty)
  916. {
  917. dtx/=abs(dty);
  918. dty/=abs(dty);
  919. }
  920. else if(dtx>0)
  921. dtx=1;
  922. else if(dtx<0)
  923. dtx=-1;
  924. }
  925. else
  926. {
  927. if(dtx)
  928. {
  929. dty/=abs(dtx);
  930. dtx/=abs(dtx);
  931. }
  932. else if(dty>0)
  933. dty=1;
  934. else if(dtx<0)
  935. dty=-1;
  936. }
  937. if(dtx>3)
  938. {
  939. double step=dtx/3.0;
  940. dtx/=step;
  941. dty/=step;
  942. }
  943. if(dty>3)
  944. {
  945. double step=dty/3.0;
  946. dtx/=step;
  947. dty/=step;
  948. }
  949. BOOL bFind=0;
  950. while(1)
  951. {
  952. x+=dtx;
  953. y+=dty;
  954. if(x>=(rc.Width-1) || x<1)break;
  955. if(y>=(rc.Height-1) || y<1)break;
  956. if(col>x0)
  957. {
  958. if(x<x0)
  959. {
  960. break;
  961. }
  962. if(x>col)
  963. {
  964. break;
  965. }
  966. }
  967. if(col<x0)
  968. {
  969. if(x>x0)
  970. {
  971. break;
  972. }
  973. if(x<col)
  974. {
  975. break;
  976. }
  977. }
  978. if(row>y0)
  979. {
  980. if(y<y0)
  981. {
  982. break;
  983. }
  984. if(y>row)
  985. {
  986. break;
  987. }
  988. }
  989. if(row<y0)
  990. {
  991. if(y>y0)
  992. {
  993. break;
  994. }
  995. if(y<row)
  996. {
  997. break;
  998. }
  999. }
  1000. color.SetValue(pixels[(int)y * wids + (int)x]);
  1001. if(color.GetA()==255)
  1002. {
  1003. color1.SetValue(pixels[(int)(y-1) * wids + (int)(x-1)]);
  1004. color2.SetValue(pixels[(int)(y-1) * wids + (int)(x-0)]);
  1005. color3.SetValue(pixels[(int)(y-1) * wids + (int)(x+1)]);
  1006. color4.SetValue(pixels[(int)(y-0) * wids + (int)(x-1)]);
  1007. color5.SetValue(pixels[(int)(y-0) * wids + (int)(x+1)]);
  1008. color6.SetValue(pixels[(int)(y+1) * wids + (int)(x-1)]);
  1009. color7.SetValue(pixels[(int)(y+1) * wids + (int)(x-0)]);
  1010. color8.SetValue(pixels[(int)(y+1) * wids + (int)(x+1)]);
  1011. 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)
  1012. {
  1013. bFind=1;
  1014. break;
  1015. }
  1016. }
  1017. }
  1018. if(bFind==0)
  1019. pArray=&(m_rcarray[aa]);
  1020. }
  1021. }
  1022. if(pArray==NULL)
  1023. {
  1024. BOOL bcontinue=1;
  1025. for(int yy=0; yy<RCARRARCOUNT; yy++)
  1026. {
  1027. if(m_rcarray[yy].GetSize()==0)
  1028. {
  1029. pArray=&(m_rcarray[yy]);
  1030. bcontinue=0;
  1031. break;
  1032. }
  1033. }
  1034. if(bcontinue)continue;
  1035. }
  1036. pArray->Add(col); // x坐标;
  1037. pArray->Add(row); // y坐标;
  1038. }
  1039. }
  1040. }
  1041. pBmpImage->UnlockBits(&bitmapData);
  1042. if(bdelete)delete pBmpImage;
  1043. /*
  1044. if(pBmpImage==NULL)return;
  1045. BitmapData bitmapData;
  1046. UINT* pixels;
  1047. Rect rc(0, 0, pBmpImage->GetWidth(), pBmpImage->GetHeight() );
  1048. pBmpImage->LockBits(
  1049. rc,
  1050. ImageLockModeRead,
  1051. PixelFormat32bppARGB,
  1052. &bitmapData);
  1053. // Write to the temporary buffer provided by LockBits. RGB
  1054. pixels = (UINT*)bitmapData.Scan0;
  1055. DWORD wids=bitmapData.Stride/4;
  1056. Color color;
  1057. Color color1,color2,color3,color4,color5,color6,color7,color8;
  1058. BYTE R,G,B;
  1059. m_rcarray1.RemoveAll ();
  1060. m_rcarray2.RemoveAll ();
  1061. m_rcarray3.RemoveAll ();
  1062. m_rcarray4.RemoveAll ();
  1063. m_rcarray5.RemoveAll ();
  1064. for( INT row = 0; row < rc.Height; ++row)
  1065. {
  1066. for(INT col = 0; col < rc.Width-1; ++col)
  1067. {
  1068. color.SetValue(pixels[row * wids + col]);
  1069. if(color.GetA()<200)
  1070. {
  1071. CArray<int,int>*pArray=NULL;
  1072. if(m_rcarray1.GetSize () && pArray==NULL)
  1073. {
  1074. double x=m_rcarray1.ElementAt (0);
  1075. double y=m_rcarray1.ElementAt (1);
  1076. double dtx=col-x;
  1077. double dty=row-y;
  1078. dtx/=10.0;dty/=10.0;
  1079. BOOL bFind=0;
  1080. for(int a=0; a<10; a++)
  1081. {
  1082. x+=dtx;
  1083. y+=dty;
  1084. color.SetValue(pixels[(int)y * wids + (int)x]);
  1085. if(color.GetA()==255)
  1086. {
  1087. color1.SetValue(pixels[(int)(y-1) * wids + (int)(x-1)]);
  1088. color2.SetValue(pixels[(int)(y-1) * wids + (int)(x-0)]);
  1089. color3.SetValue(pixels[(int)(y-1) * wids + (int)(x+1)]);
  1090. color4.SetValue(pixels[(int)(y-0) * wids + (int)(x-1)]);
  1091. color5.SetValue(pixels[(int)(y-0) * wids + (int)(x+1)]);
  1092. color6.SetValue(pixels[(int)(y+1) * wids + (int)(x-1)]);
  1093. color7.SetValue(pixels[(int)(y+1) * wids + (int)(x-0)]);
  1094. color8.SetValue(pixels[(int)(y+1) * wids + (int)(x+1)]);
  1095. 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)
  1096. {
  1097. bFind=1;
  1098. break;
  1099. }
  1100. }
  1101. }
  1102. if(bFind==0)pArray=&m_rcarray1;
  1103. }
  1104. if(m_rcarray2.GetSize () && pArray==NULL)
  1105. {
  1106. double x=m_rcarray2.ElementAt (0);
  1107. double y=m_rcarray2.ElementAt (1);
  1108. double dtx=col-x;dtx/=10.0;
  1109. double dty=row-y;dty/=10.0;
  1110. BOOL bFind=0;
  1111. for(int a=0; a<10; a++)
  1112. {
  1113. x+=dtx;
  1114. y+=dty;
  1115. color.SetValue(pixels[(int)y * wids + (int)x]);
  1116. if(color.GetA()==255)
  1117. {
  1118. color1.SetValue(pixels[(int)(y-1) * wids + (int)(x-1)]);
  1119. color2.SetValue(pixels[(int)(y-1) * wids + (int)(x-0)]);
  1120. color3.SetValue(pixels[(int)(y-1) * wids + (int)(x+1)]);
  1121. color4.SetValue(pixels[(int)(y-0) * wids + (int)(x-1)]);
  1122. color5.SetValue(pixels[(int)(y-0) * wids + (int)(x+1)]);
  1123. color6.SetValue(pixels[(int)(y+1) * wids + (int)(x-1)]);
  1124. color7.SetValue(pixels[(int)(y+1) * wids + (int)(x-0)]);
  1125. color8.SetValue(pixels[(int)(y+1) * wids + (int)(x+1)]);
  1126. 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)
  1127. {
  1128. bFind=1;
  1129. break;
  1130. }
  1131. }
  1132. }
  1133. if(bFind==0)pArray=&m_rcarray2;
  1134. }
  1135. if(m_rcarray3.GetSize () && pArray==NULL)
  1136. {
  1137. double x=m_rcarray3.ElementAt (0);
  1138. double y=m_rcarray3.ElementAt (1);
  1139. double dtx=col-x;dtx/=10.0;
  1140. double dty=row-y;dty/=10.0;
  1141. BOOL bFind=0;
  1142. for(int a=0; a<10; a++)
  1143. {
  1144. x+=dtx;
  1145. y+=dty;
  1146. color.SetValue(pixels[(int)y * wids + (int)x]);
  1147. if(color.GetA()==255)
  1148. {
  1149. color1.SetValue(pixels[(int)(y-1) * wids + (int)(x-1)]);
  1150. color2.SetValue(pixels[(int)(y-1) * wids + (int)(x-0)]);
  1151. color3.SetValue(pixels[(int)(y-1) * wids + (int)(x+1)]);
  1152. color4.SetValue(pixels[(int)(y-0) * wids + (int)(x-1)]);
  1153. color5.SetValue(pixels[(int)(y-0) * wids + (int)(x+1)]);
  1154. color6.SetValue(pixels[(int)(y+1) * wids + (int)(x-1)]);
  1155. color7.SetValue(pixels[(int)(y+1) * wids + (int)(x-0)]);
  1156. color8.SetValue(pixels[(int)(y+1) * wids + (int)(x+1)]);
  1157. 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)
  1158. {
  1159. bFind=1;
  1160. break;
  1161. }
  1162. }
  1163. }
  1164. if(bFind==0)pArray=&m_rcarray3;
  1165. }
  1166. if(m_rcarray4.GetSize () && pArray==NULL)
  1167. {
  1168. double x=m_rcarray4.ElementAt (0);
  1169. double y=m_rcarray4.ElementAt (1);
  1170. double dtx=col-x;dtx/=10.0;
  1171. double dty=row-y;dty/=10.0;
  1172. BOOL bFind=0;
  1173. for(int a=0; a<10; a++)
  1174. {
  1175. x+=dtx;
  1176. y+=dty;
  1177. color.SetValue(pixels[(int)y * wids + (int)x]);
  1178. if(color.GetA()==255)
  1179. {
  1180. color1.SetValue(pixels[(int)(y-1) * wids + (int)(x-1)]);
  1181. color2.SetValue(pixels[(int)(y-1) * wids + (int)(x-0)]);
  1182. color3.SetValue(pixels[(int)(y-1) * wids + (int)(x+1)]);
  1183. color4.SetValue(pixels[(int)(y-0) * wids + (int)(x-1)]);
  1184. color5.SetValue(pixels[(int)(y-0) * wids + (int)(x+1)]);
  1185. color6.SetValue(pixels[(int)(y+1) * wids + (int)(x-1)]);
  1186. color7.SetValue(pixels[(int)(y+1) * wids + (int)(x-0)]);
  1187. color8.SetValue(pixels[(int)(y+1) * wids + (int)(x+1)]);
  1188. 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)
  1189. {
  1190. bFind=1;
  1191. break;
  1192. }
  1193. }
  1194. }
  1195. if(bFind==0)pArray=&m_rcarray4;
  1196. }
  1197. if(m_rcarray5.GetSize () && pArray==NULL)
  1198. {
  1199. double x=m_rcarray5.ElementAt (0);
  1200. double y=m_rcarray5.ElementAt (1);
  1201. double dtx=col-x;dtx/=10.0;
  1202. double dty=row-y;dty/=10.0;
  1203. BOOL bFind=0;
  1204. for(int a=0; a<10; a++)
  1205. {
  1206. x+=dtx;
  1207. y+=dty;
  1208. color.SetValue(pixels[(int)y * wids + (int)x]);
  1209. if(color.GetA()==255)
  1210. {
  1211. color1.SetValue(pixels[(int)(y-1) * wids + (int)(x-1)]);
  1212. color2.SetValue(pixels[(int)(y-1) * wids + (int)(x-0)]);
  1213. color3.SetValue(pixels[(int)(y-1) * wids + (int)(x+1)]);
  1214. color4.SetValue(pixels[(int)(y-0) * wids + (int)(x-1)]);
  1215. color5.SetValue(pixels[(int)(y-0) * wids + (int)(x+1)]);
  1216. color6.SetValue(pixels[(int)(y+1) * wids + (int)(x-1)]);
  1217. color7.SetValue(pixels[(int)(y+1) * wids + (int)(x-0)]);
  1218. color8.SetValue(pixels[(int)(y+1) * wids + (int)(x+1)]);
  1219. 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)
  1220. {
  1221. bFind=1;
  1222. break;
  1223. }
  1224. }
  1225. }
  1226. if(bFind==0)pArray=&m_rcarray5;
  1227. }
  1228. if(pArray==NULL)
  1229. {
  1230. if(m_rcarray1.GetSize ()==0)
  1231. pArray=&m_rcarray1;
  1232. else if(m_rcarray2.GetSize ()==0)
  1233. pArray=&m_rcarray2;
  1234. else if(m_rcarray3.GetSize ()==0)
  1235. pArray=&m_rcarray3;
  1236. else if(m_rcarray4.GetSize ()==0)
  1237. pArray=&m_rcarray4;
  1238. else if(m_rcarray5.GetSize ()==0)
  1239. pArray=&m_rcarray5;
  1240. else continue;
  1241. }
  1242. pArray->Add (col);pArray->Add (row);
  1243. }
  1244. }
  1245. }
  1246. pBmpImage->UnlockBits(&bitmapData);
  1247. */
  1248. }