1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423 |
- #include "stdafx.h"
- #include "ylgl.h"
- #include "ShowEffect.h"
- #include <math.h>
- #include "InputName.h"
- #define THUMBNAIL_WIDTH 60
- #define THUMBNAIL_HEIGHT 50
- ShowEffectDlg::ShowEffectDlg(CWnd* pParent )
- : CDialog(ShowEffectDlg::IDD, pParent)
- {
-
-
- m_pbmp=NULL;
- m_pImage=NULL;
- m_pImagebak=NULL;
- m_pPhoto=NULL;
-
- m_effectpos=0;
- m_photopos=0;
- m_fscale=1.0;
- m_bTerminate=false;
- m_bRunning=false;
- m_hThread = NULL;
- m_bTerminate2=false;
- m_bRunning2=false;
- m_hThread2 = NULL;
- m_bLoadEffect=1;
- m_bLoadPhoto=1;
- }
- void ShowEffectDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
-
- DDX_Control(pDX, IDC_LIST2, m_List2);
- DDX_Control(pDX, IDC_LIST1, m_List1);
-
- }
- BEGIN_MESSAGE_MAP(ShowEffectDlg, CDialog)
-
- ON_WM_DESTROY()
- ON_WM_PAINT()
- ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
- ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
- ON_WM_LBUTTONDOWN()
- ON_WM_MOUSEMOVE()
- ON_WM_LBUTTONUP()
- ON_WM_MOUSEWHEEL()
- ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
- ON_WM_TIMER()
- ON_NOTIFY(NM_CLICK, IDC_LIST2, OnClickList2)
-
- END_MESSAGE_MAP()
- unsigned __stdcall LoadThumbNail17(LPVOID lpParam)
- {
- try
- {
- ShowEffectDlg *pDlg=(ShowEffectDlg*)lpParam;
- CListCtrl *ListCtrl=&pDlg->m_List2;
- CImageList* pImgList=&pDlg->m_ImageListThumb2;
-
- for(int i=0; i<pImgList->GetImageCount(); i++)
- pImgList->Remove(i);
-
- ListCtrl->DeleteAllItems();
- pImgList->SetImageCount(pDlg->m_vFileName2.size());
- TCHAR path[MAX_PATH];
- vector<CString>::iterator iter;
-
- ListCtrl->SetRedraw(FALSE);
- int nIndex=0;
- CString str, spath;
- for(iter=pDlg->m_vFileName2.begin(); iter!=pDlg->m_vFileName2.end() && pDlg->m_bTerminate2!=true; iter++, nIndex++)
- {
- str=*iter;
- str=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
- str=str.Left (str.Find ("."));
- ListCtrl->InsertItem(nIndex, str, nIndex);
- }
- ListCtrl->SetRedraw(TRUE);
- ListCtrl->Invalidate();
- const float fRatio=(float)THUMBNAIL_HEIGHT/THUMBNAIL_WIDTH;
- int XDest, YDest, nDestWidth, nDestHeight;
- nIndex=0;
- SolidBrush whitebrush(Color(255,255,255,255));
- for(iter=pDlg->m_vFileName2.begin(); iter!=pDlg->m_vFileName2.end() && pDlg->m_bTerminate2!=true; iter++, nIndex++)
- {
-
- Image *image=NULL;
- Bitmap *pBmp=NULL;
- str=*iter;
- spath=str.Left (str.ReverseFind ('\\')+1);
- spath+="s";
- spath+=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
- if (PathFileExists(spath))
- ::LoadImageFromBuf (&image, spath);
- else
- ::LoadImageFromBuf (&image, str);
- int orientation=GetOrientation(image);
- if(orientation==8)
- image->RotateFlip( Rotate270FlipNone );
- else if(orientation==6)
- image->RotateFlip( Rotate90FlipNone );
- if(image->GetWidth()==0)
- continue;
-
- const float fImgRatio=(float)image->GetHeight()/image->GetWidth();
- if(fImgRatio > fRatio)
- {
- nDestWidth=THUMBNAIL_HEIGHT/fImgRatio;
- XDest=(THUMBNAIL_WIDTH-nDestWidth)/2;
- YDest=0;
- nDestHeight=THUMBNAIL_HEIGHT;
- }
- else
- {
- XDest=0;
- nDestWidth=THUMBNAIL_WIDTH;
- nDestHeight=THUMBNAIL_WIDTH*fImgRatio;
- YDest=(THUMBNAIL_HEIGHT-nDestHeight)/2;
- }
- pBmp=new Bitmap(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, PixelFormat24bppRGB );
- Graphics graph2(pBmp);
- graph2.Clear(Color(255,192,192,192));
- graph2.FillRectangle (&whitebrush,1, 1, THUMBNAIL_WIDTH-2, THUMBNAIL_HEIGHT-2);
- Graphics graph(pBmp);
- Rect desRect(XDest, YDest, nDestWidth, nDestHeight);
-
- graph.DrawImage(image, desRect, 0,0,image->GetWidth(),image->GetHeight(),UnitPixel);
- delete image;
-
- CBitmap bitmap;
- HBITMAP hbmp;
- pBmp->GetHBITMAP(Color(255,255,255,255), &hbmp);
- bitmap.Attach(hbmp);
- pImgList->Replace(nIndex, &bitmap, NULL);
- delete pBmp;
-
- ListCtrl->RedrawItems(nIndex, nIndex);
-
- }
- ListCtrl->Invalidate();
- pDlg->m_bRunning2=false;
- pDlg->m_bTerminate2=false;
- _endthreadex( 0 );
- return 0;
- }
- catch(...)
- {
- }
- }
- unsigned __stdcall LoadThumbNail16(LPVOID lpParam)
- {
- try
- {
- ShowEffectDlg *pDlg=(ShowEffectDlg*)lpParam;
- CListCtrl *ListCtrl=&pDlg->m_List1;
- CImageList* pImgList=&pDlg->m_ImageListThumb;
-
- for(int i=0; i<pImgList->GetImageCount(); i++)
- pImgList->Remove(i);
-
- ListCtrl->DeleteAllItems();
- pImgList->SetImageCount(pDlg->m_vFileName.size());
- TCHAR path[MAX_PATH];
- vector<CString>::iterator iter;
-
- ListCtrl->SetRedraw(FALSE);
- int nIndex=0;
- CString str, spath;
- for(iter=pDlg->m_vFileName.begin(); iter!=pDlg->m_vFileName.end() && pDlg->m_bTerminate!=true; iter++, nIndex++)
- {
- str=*iter;
- str=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
- str=str.Left (str.Find ("."));
- ListCtrl->InsertItem(nIndex, str, nIndex);
- }
- ListCtrl->SetRedraw(TRUE);
- ListCtrl->Invalidate();
- const float fRatio=(float)THUMBNAIL_HEIGHT/THUMBNAIL_WIDTH;
- int XDest, YDest, nDestWidth, nDestHeight;
- nIndex=0;
- SolidBrush whitebrush(Color(255,255,255,255));
- for(iter=pDlg->m_vFileName.begin(); iter!=pDlg->m_vFileName.end() && pDlg->m_bTerminate!=true; iter++, nIndex++)
- {
-
- Image *image=NULL;
- Bitmap *pBmp=NULL;
- str=*iter;
- spath=str.Left (str.ReverseFind ('\\')+1);
- spath+="s";
- spath+=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
- spath.Replace ("png","jpg");
- if (PathFileExists(spath))
- {
- ::LoadImageFromBuf (&image, spath);
- }
- else
- ::LoadImageFromBuf (&image, str);
- int orientation=GetOrientation(image);
- if(orientation==8)
- image->RotateFlip( Rotate270FlipNone );
- else if(orientation==6)
- image->RotateFlip( Rotate90FlipNone );
- if(image->GetWidth()==0)
- continue;
-
- const float fImgRatio=(float)image->GetHeight()/image->GetWidth();
- if(fImgRatio > fRatio)
- {
- nDestWidth=THUMBNAIL_HEIGHT/fImgRatio;
- XDest=(THUMBNAIL_WIDTH-nDestWidth)/2;
- YDest=0;
- nDestHeight=THUMBNAIL_HEIGHT;
- }
- else
- {
- XDest=0;
- nDestWidth=THUMBNAIL_WIDTH;
- nDestHeight=THUMBNAIL_WIDTH*fImgRatio;
- YDest=(THUMBNAIL_HEIGHT-nDestHeight)/2;
- }
- pBmp=new Bitmap(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, PixelFormat24bppRGB );
- Graphics graph2(pBmp);
- graph2.Clear(Color(255,192,192,192));
- graph2.FillRectangle (&whitebrush,1, 1, THUMBNAIL_WIDTH-2, THUMBNAIL_HEIGHT-2);
- Graphics graph(pBmp);
- Rect desRect(XDest, YDest, nDestWidth, nDestHeight);
-
- graph.DrawImage(image, desRect, 0,0,image->GetWidth(),image->GetHeight(),UnitPixel);
- delete image;
-
- CBitmap bitmap;
- HBITMAP hbmp;
- pBmp->GetHBITMAP(Color(255,255,255,255), &hbmp);
- bitmap.Attach(hbmp);
- pImgList->Replace(nIndex, &bitmap, NULL);
- delete pBmp;
-
- ListCtrl->RedrawItems(nIndex, nIndex);
-
- }
- ListCtrl->Invalidate();
- pDlg->m_bRunning=false;
- pDlg->m_bTerminate=false;
- _endthreadex( 0 );
- return 0;
- }
- catch(...)
- {
- }
- }
- BOOL ShowEffectDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- GetDlgItem(IDC_BUTTON2)->EnableWindow(IsHasRights2new(49));
- using namespace helper_coffs;
- ffsco o;
- o.dirs(0);
- o.find(LPCSTR(g_path7), LPCSTR("*.png"));
- ffsco::typeT coo;
- ffsco::typeT::iterator it;
- coo = o.co_file();
- for (it = coo.begin(); coo.end() != it; it ++)
- {
- m_effectpatharray.Add ((*it).c_str());
- }
- if(m_effectpatharray.GetSize()==0)
- {
- AfxMessageBox("您还没有安装效果图!", MB_ICONINFORMATION);
- ::CreateDirectory (g_path7, NULL);
-
-
- }
-
-
- ::SetWindowPos(m_hWnd,HWND_TOP,0 ,0,g_screenwid,g_screenhei,SWP_SHOWWINDOW);
- m_rcscreen=CRect(0, 0, g_screenwid, g_screenhei);
-
-
-
- CRect rc,rc2,rc3;
- GetClientRect(rc2);
- GetDlgItem(IDC_BUTTON1)->GetWindowRect(rc3);
- ScreenToClient(rc3);
- rc=rc2;
- rc.right =110;
- rc.top =rc3.bottom +rc3.top;
- m_List1.MoveWindow(rc);
- rc=rc2;
- rc.left=rc.right-110;
- m_List2.MoveWindow(rc);
-
- rc=rc2;
- rc.left +=110;
- rc.right -=110;
- m_pbmp=new Bitmap(rc.Width (), rc.Height (), PixelFormat24bppRGB );
- m_ImageListThumb.Create(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, ILC_COLOR24, 0, 1);
- m_List1.SetImageList(&m_ImageListThumb, LVSIL_NORMAL);
- m_ImageListThumb2.Create(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, ILC_COLOR24, 0, 1);
- m_List2.SetImageList(&m_ImageListThumb2, LVSIL_NORMAL);
- if(m_bRunning)return 0;
- CStringArray *pArray=&m_effectpatharray;
- m_vFileName.clear();
- for(int i=0; i<pArray->GetSize (); i++)
- {
- CString filePath=pArray->ElementAt (i);
- filePath.MakeLower();
- m_vFileName.push_back(filePath);
- }
- TerminateThread();
- m_hThread = (HANDLE)_beginthreadex(NULL,0, LoadThumbNail16,(LPVOID)this,0,&m_dwThreadID);
- m_bRunning=true;
- {
- if(m_bRunning2)return 0;
- CStringArray *pArray=m_pPhotopatharray;
- m_vFileName2.clear();
- for(int i=0; i<pArray->GetSize (); i++)
- {
- CString filePath=pArray->ElementAt (i);
- filePath.MakeLower();
- m_vFileName2.push_back(filePath);
- }
- TerminateThread2();
- m_hThread2 = (HANDLE)_beginthreadex(NULL,0, LoadThumbNail17,(LPVOID)this,0,&m_dwThreadID2);
- m_bRunning2=true;
- }
- SetTimer(1, 200, NULL);
- return TRUE;
-
- }
- BOOL ShowEffectDlg::TerminateThread()
- {
- if ( !m_bRunning )
- return TRUE;
- m_bTerminate=true;
- for( ; ; )
- {
- if ( ::WaitForSingleObject(m_hThread, 0) == WAIT_OBJECT_0 )
- break;
- MSG msg;
- while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
- {
- if (!AfxGetApp()->PumpMessage())
- break;
- }
- }
- ::CloseHandle(m_hThread);
- return TRUE;
- }
- BOOL ShowEffectDlg::TerminateThread2()
- {
- if ( !m_bRunning2 )
- return TRUE;
- m_bTerminate2=true;
- for( ; ; )
- {
- if ( ::WaitForSingleObject(m_hThread2, 0) == WAIT_OBJECT_0 )
- break;
- MSG msg;
- while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
- {
- if (!AfxGetApp()->PumpMessage())
- break;
- }
- }
- ::CloseHandle(m_hThread2);
- return TRUE;
- }
- void ShowEffectDlg::OnDestroy()
- {
-
- TerminateThread2();
- TerminateThread();
- if(m_pbmp) delete m_pbmp;m_pbmp=NULL;
- if(m_pImage)delete m_pImage;m_pImage=NULL;
- if(m_pImagebak)delete m_pImagebak;m_pImagebak=NULL;
- if(m_pPhoto)delete m_pPhoto;m_pPhoto=NULL;
- CDialog::OnDestroy();
- }
- void ShowEffectDlg::OnPaint()
- {
- CPaintDC dc(this);
-
- try
- {
- if(m_pbmp)
- {
- Graphics graph2(dc.GetSafeHdc ());
- graph2.DrawImage(m_pbmp,110,0);
- }
- }
- catch(...)
- {
- }
-
- }
- BOOL ShowEffectDlg::OnEraseBkgnd(CDC* pDC)
- {
-
- return 1;
- }
- void ShowEffectDlg::InitRc(Image *img)
- {
- try
- {
- if(img==NULL)return;
- CRect rc;
- GetClientRect(rc);
- rc.right -=220;
- m_rc=rc;
- int width,height;
- width=img->GetWidth();
- height=img->GetHeight();
-
- float fscale=(float)width/(float)height;
- float rcscale=((float)m_rc.Width ())/((float)m_rc.Height ());
- int rcwid=m_rc.Width ();
- int rchei=m_rc.Height ();
- int dt=0;
- if(rcscale<fscale)
- {
- dt=(rchei-rcwid/fscale)/2;
- m_rc.top+=dt;
- m_rc.bottom-=dt;
- }
- else
- {
- dt=(rcwid-rchei*fscale)/2;
- m_rc.left +=dt;
- m_rc.right-=dt;
- }
- m_rcbak=m_rc;
- }
- catch(...)
- {
- }
- }
- void ShowEffectDlg::RcChange()
- {
- }
- int GetFileNo2()
- {
- CString path;
- int begin=1;
- path.Format ("%s\\效果图-%d.png", g_path7, begin);
- while (PathFileExists(path))
- {
- begin++;
- path.Format ("%s\\效果图-%d.png", g_path7, begin);
- }
- return begin;
- }
- extern void SaveImageToFile(Image *img, CString path);
- void ShowEffectDlg::OnButton1()
- {
- if(AfxMessageBox("制作方法:\r\n1.图片格式为透明PNG格式.\r\n2.显示客照的位置为透明.", MB_ICONINFORMATION));
- CFileDialog fdlg(true, NULL,"openfile", OFN_ALLOWMULTISELECT,"png文件(*.png)|*.png||");
- TCHAR szBuffer[60000]={0};
- fdlg.m_ofn.lpstrFile = szBuffer;
- fdlg.m_ofn.nMaxFile = 60000;
- if(fdlg.DoModal ()!=IDOK)
- {
- return;
- }
- POSITION pos=fdlg.GetStartPosition ();
- CStringArray array;
- while(pos!=NULL)
- {
- array.Add(fdlg.GetNextPathName (pos));
- }
- if(array.GetSize ()==0)return;
- for(int i=0; i<array.GetSize (); i++)
- {
- Bitmap *img=NULL;
- ::LoadImageFromBuf (&img, array.ElementAt (i));
- if(img==NULL)continue;
- if(img->GetWidth()==0)continue;
- if(img->GetWidth()>2000 || img->GetHeight()>2000)
- {
- CRect rc(0,0,2000,2000);
- RectFitDes(img->GetWidth(), img->GetHeight(), rc);
- Bitmap *simg=new Bitmap(rc.Width (), rc.Height (), PixelFormat32bppARGB );
- Graphics graphic(simg);
- graphic.Clear(Color(0,0,0,0));
- graphic.DrawImage(img, 0,0,simg->GetWidth(), simg->GetHeight() );
- delete img;
- img=simg;
- }
- CString path;
- CString str=array.ElementAt (i);
- str=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
- str=str.Left (str.Find ("."));
-
- path.Format ("%s\\%s.png", g_path7, str);
-
- ::SaveImageToFile (img, path);
- str=path;
- CString spath=str.Left (str.ReverseFind ('\\')+1);
- spath+="s";
- spath+=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
- spath.Replace ("png","jpg");
- CRect rc(0,0,100,100);
- RectFitDes(img->GetWidth(), img->GetHeight(), rc);
- Bitmap *simg=new Bitmap(rc.Width (), rc.Height (), PixelFormat32bppARGB );
- Graphics graphic(simg);graphic.Clear(Color(0,0,0,0));
- graphic.DrawImage(img, 0,0,simg->GetWidth(), simg->GetHeight() );
- ::SaveImageToFile (simg, spath);
- delete img;delete simg;
- }
- m_effectpos=0;
- m_photopos=0;
- m_effectpatharray.RemoveAll ();
- using namespace helper_coffs;
- ffsco o;
- o.dirs(0);
- o.find(LPCSTR(g_path7), LPCSTR("*.png"));
- ffsco::typeT coo;
- ffsco::typeT::iterator it;
- coo = o.co_file();
- for (it = coo.begin(); coo.end() != it; it ++)
- {
- m_effectpatharray.Add ((*it).c_str());
- }
- if(m_effectpatharray.GetSize()==0)
- {
- AfxMessageBox("您还没有安装效果图!", MB_ICONINFORMATION);
- ::CreateDirectory (g_path7, NULL);
- }
- TerminateThread();
- CStringArray *pArray=&m_effectpatharray;
- m_vFileName.clear();
- for( i=0; i<pArray->GetSize (); i++)
- {
- CString filePath=pArray->ElementAt (i);
- filePath.MakeLower();
- m_vFileName.push_back(filePath);
- }
- m_hThread = (HANDLE)_beginthreadex(NULL,0, LoadThumbNail16,(LPVOID)this,0,&m_dwThreadID);
- m_bRunning=true;
- }
- void ShowEffectDlg::OnButton2()
- {
- POSITION pos;
- pos=m_List1.GetFirstSelectedItemPosition();
- if(pos==NULL)
- {
- return;
- }
- int selpos=m_List1.GetNextSelectedItem(pos);
- if(AfxMessageBox("确认删除吗?", MB_YESNO|MB_ICONINFORMATION)!=IDYES)return;
- CString str=m_effectpatharray.ElementAt (selpos);
- CString spath=str.Left (str.ReverseFind ('\\')+1);
- spath+="s";
- spath+=str.Right (str.GetLength ()-str.ReverseFind ('\\')-1);
- spath.Replace ("png","jpg");
- ::DeleteFile(str);
- ::DeleteFile(spath);
- m_effectpatharray.RemoveAt (selpos);
- m_List1.DeleteItem (selpos); m_effectpos=0;
- m_photopos=0;
- }
- void ShowEffectDlg::OnLButtonDown(UINT nFlags, CPoint point)
- {
-
-
-
- CDialog::OnLButtonDown(nFlags, point);
- }
- void ShowEffectDlg::OnMouseMove(UINT nFlags, CPoint point)
- {
-
-
- CDialog::OnMouseMove(nFlags, point);
- }
- void ShowEffectDlg::OnLButtonUp(UINT nFlags, CPoint point)
- {
-
-
- CDialog::OnLButtonUp(nFlags, point);
- }
- BOOL ShowEffectDlg::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
- {
-
-
- return CDialog::OnMouseWheel(nFlags, zDelta, pt);
- }
- void ShowEffectDlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
- {
-
- POSITION pos;
- pos=m_List1.GetFirstSelectedItemPosition();
- if(pos==NULL)
- {
- return;
- }
- m_effectpos=m_List1.GetNextSelectedItem(pos);m_bLoadEffect=1;
- MakeEffect();
- *pResult = 0;
- }
- void ShowEffectDlg::OnTimer(UINT nIDEvent)
- {
-
- KillTimer(nIDEvent);
- MakeEffect();
- }
- void ShowEffectDlg::OnClickList2(NMHDR* pNMHDR, LRESULT* pResult)
- {
-
- POSITION pos;
- pos=m_List2.GetFirstSelectedItemPosition();
- if(pos==NULL)
- {
- return;
- }
- m_photopos=m_List2.GetNextSelectedItem(pos); m_bLoadPhoto=1;
- MakeEffect();
- *pResult = 0;
- }
- int GetLengFromPt(CPoint pt1, CPoint pt2)
- {
- return (pt1.x-pt2.x)*(pt1.x-pt2.x)+(pt1.y-pt2.y)*(pt1.y-pt2.y);
- }
- int GetLengFromPt2(CPoint pt1, CPoint pt2)
- {
- return sqrt((pt1.x-pt2.x)*(pt1.x-pt2.x)+(pt1.y-pt2.y)*(pt1.y-pt2.y));
- }
- void ShowEffectDlg::MakeEffect()
- {
-
- if(m_effectpatharray.GetSize()==0)return;
-
- Graphics graph(m_pbmp);
-
- graph.Clear(Color(255,255,255,255));
- if(m_bLoadPhoto)
- {
- if(m_pPhoto)delete m_pPhoto;m_pPhoto=NULL;
- }
- if(m_bLoadEffect)
- {
- if(m_pImage)delete m_pImage;m_pImage=NULL;
- if(m_pImagebak)delete m_pImagebak;m_pImagebak=NULL;
-
- ::LoadImageFromBuf(&m_pImage, m_effectpatharray.ElementAt(m_effectpos));
- if(m_pPhotopatharray->GetSize())
- GetRgn(m_pImage);
- m_pImagebak = m_pImage->Clone(0,0,m_pImage->GetWidth(),m_pImage->GetHeight(),PixelFormat32bppARGB );
- }
- int width,height;
- width=m_pImage->GetWidth();
- height=m_pImage->GetHeight();
- if(width==0 || height==0)return;
- InitRc(m_pImage);
- CPoint pt1,pt2,pt3;
- int leng1,leng2,leng3;
- CPoint curpt;
- int leng;
- Graphics graph2(m_pImage);
-
- if(m_pPhotopatharray->GetSize ())
- {
- if(m_bLoadPhoto)
- ::LoadImageFromBuf (&m_pPhoto, m_pPhotopatharray->ElementAt (m_photopos));
- int i;
- for(int aa=0; aa<RCARRARCOUNT; aa++)
- {
- leng1=leng2=leng3=10000000;
- for( i=0; i<m_rcarray[aa].GetSize (); i+=2)
- {
- curpt.x=m_rcarray[aa].ElementAt (i);
- curpt.y=m_rcarray[aa].ElementAt (i+1);
- leng=GetLengFromPt(CPoint(0,0), curpt);
- if(leng<leng1)
- {
- leng1=leng;
- pt1=curpt;
- }
- leng=GetLengFromPt(CPoint(m_pImage->GetWidth(),0), curpt);
- if(leng<leng2)
- {
- leng2=leng;
- pt2=curpt;
- }
- leng=GetLengFromPt(CPoint(0,m_pImage->GetHeight()), curpt);
- if(leng<leng3)
- {
- leng3=leng;
- pt3=curpt;
- }
- }
- if(m_rcarray[aa].GetSize ())
- {
- pt1.x*=m_tempscale;
- pt1.y*=m_tempscale;
- pt2.x*=m_tempscale;
- pt2.y*=m_tempscale;
- pt3.x*=m_tempscale;
- pt3.y*=m_tempscale;
- Point destinationPoints[] = {
- Point(pt1.x, pt1.y),
- Point(pt2.x, pt2.y),
- Point(pt3.x, pt3.y)};
-
- int lengx=GetLengFromPt2(pt1, pt2);
- int lengy=GetLengFromPt2(pt1, pt3);
-
- CRect rc(0,0,m_pPhoto->GetWidth(),m_pPhoto->GetHeight());
- RectFitDes(lengx,lengy,rc);
- graph2.DrawImage(
- m_pPhoto,
- destinationPoints,
- 3,
- rc.left,
- rc.top,
- rc.Width(),
- rc.Height(),
- UnitPixel,
- NULL,
- NULL,
- NULL);
- }
- }
-
- graph2.DrawImage(m_pImagebak, 0, 0);
- }
- Rect destinationRect( m_rc.left , m_rc.top , m_rc.Width (), m_rc.Height () );
- graph.DrawImage(m_pImage, destinationRect, 0,0,width,height,UnitPixel);
- CRect rc;
- GetClientRect(rc);
- rc.left +=110;
- rc.right -=110;
- InvalidateRect(rc);
- m_bLoadEffect=0;
- m_bLoadPhoto=0;
- }
- void ShowEffectDlg::GetRgn(Bitmap *pBmpImage2)
- {
- m_tempscale=1.0;
- if(pBmpImage2==NULL)return;
-
- Bitmap *pBmpImage=NULL;
- BOOL bdelete=0;
-
-
- if(pBmpImage2->GetWidth()>800 || pBmpImage2->GetHeight()>800)
- {
- bdelete=1;
- CRect rc(0,0,800,800);
-
- RectFitDes(pBmpImage2->GetWidth(), pBmpImage2->GetHeight(), rc);
-
- pBmpImage=new Bitmap(rc.Width (), rc.Height (), PixelFormat32bppARGB );
- Graphics graphic(pBmpImage);
- graphic.Clear(Color(0,0,0,0));
- graphic.DrawImage(pBmpImage2, 0,0,pBmpImage->GetWidth(), pBmpImage->GetHeight() );
- m_tempscale=(float)pBmpImage2->GetWidth()/(float)pBmpImage->GetWidth();
- }
- else
- pBmpImage=pBmpImage2;
-
- BitmapData bitmapData;
- UINT* pixels;
- Rect rc(0, 0, pBmpImage->GetWidth(), pBmpImage->GetHeight() );
-
- pBmpImage->LockBits(
- rc,
- ImageLockModeRead,
- PixelFormat32bppARGB,
- &bitmapData);
-
-
- pixels = (UINT*)bitmapData.Scan0;
-
-
- DWORD wids=bitmapData.Stride/4;
- Color color;
- Color color1,color2,color3,color4,color5,color6,color7,color8;
-
- BYTE R,G,B;
- for(int aa=0; aa<RCARRARCOUNT; aa++)
- m_rcarray[aa].RemoveAll();
- for( INT row = 0; row < rc.Height; ++row)
- {
- for(INT col = 0; col < rc.Width-1; ++col)
- {
-
- color.SetValue(pixels[row * wids + col]);
-
-
- if(color.GetA() < 200)
- {
- CArray<int,int>*pArray=NULL;
- for(int aa=0; aa<RCARRARCOUNT; aa++)
- {
- if(m_rcarray[aa].GetSize() && pArray==NULL)
- {
- double x=m_rcarray[aa].ElementAt(0);
- double y=m_rcarray[aa].ElementAt(1);
- int x0=(int)x;
- int y0=(int)y;
-
- double dtx=col-x;
- double dty=row-y;
-
- if(abs(dtx)>abs(dty))
- {
- if(dty)
- {
- dtx/=abs(dty);
- dty/=abs(dty);
- }
- else if(dtx>0)
- dtx=1;
- else if(dtx<0)
- dtx=-1;
- }
- else
- {
- if(dtx)
- {
- dty/=abs(dtx);
- dtx/=abs(dtx);
- }
- else if(dty>0)
- dty=1;
- else if(dtx<0)
- dty=-1;
- }
- if(dtx>3)
- {
- double step=dtx/3.0;
- dtx/=step;
- dty/=step;
- }
- if(dty>3)
- {
- double step=dty/3.0;
- dtx/=step;
- dty/=step;
- }
- BOOL bFind=0;
- while(1)
- {
- x+=dtx;
- y+=dty;
- if(x>=(rc.Width-1) || x<1)break;
- if(y>=(rc.Height-1) || y<1)break;
- if(col>x0)
- {
- if(x<x0)
- {
- break;
- }
- if(x>col)
- {
- break;
- }
- }
- if(col<x0)
- {
- if(x>x0)
- {
- break;
- }
- if(x<col)
- {
- break;
- }
- }
- if(row>y0)
- {
- if(y<y0)
- {
- break;
- }
- if(y>row)
- {
- break;
- }
- }
- if(row<y0)
- {
- if(y>y0)
- {
- break;
- }
- if(y<row)
- {
- break;
- }
- }
- color.SetValue(pixels[(int)y * wids + (int)x]);
- if(color.GetA()==255)
- {
- color1.SetValue(pixels[(int)(y-1) * wids + (int)(x-1)]);
- color2.SetValue(pixels[(int)(y-1) * wids + (int)(x-0)]);
- color3.SetValue(pixels[(int)(y-1) * wids + (int)(x+1)]);
- color4.SetValue(pixels[(int)(y-0) * wids + (int)(x-1)]);
- color5.SetValue(pixels[(int)(y-0) * wids + (int)(x+1)]);
- color6.SetValue(pixels[(int)(y+1) * wids + (int)(x-1)]);
- color7.SetValue(pixels[(int)(y+1) * wids + (int)(x-0)]);
- color8.SetValue(pixels[(int)(y+1) * wids + (int)(x+1)]);
- 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)
- {
- bFind=1;
- break;
- }
- }
- }
- if(bFind==0)
- pArray=&(m_rcarray[aa]);
- }
- }
- if(pArray==NULL)
- {
- BOOL bcontinue=1;
- for(int yy=0; yy<RCARRARCOUNT; yy++)
- {
- if(m_rcarray[yy].GetSize()==0)
- {
- pArray=&(m_rcarray[yy]);
- bcontinue=0;
- break;
- }
- }
- if(bcontinue)continue;
- }
- pArray->Add(col);
- pArray->Add(row);
- }
- }
- }
- pBmpImage->UnlockBits(&bitmapData);
- if(bdelete)delete pBmpImage;
-
- }
|