// ShowEffectDlg.cpp : implementation file // #include "stdafx.h" #include "ylgl.h" #include "ShowEffect.h" #include #include "InputName.h" #define THUMBNAIL_WIDTH 60 #define THUMBNAIL_HEIGHT 50 ///////////////////////////////////////////////////////////////////////////// // ShowEffectDlg dialog ShowEffectDlg::ShowEffectDlg(CWnd* pParent /*=NULL*/) : CDialog(ShowEffectDlg::IDD, pParent) { //{{AFX_DATA_INIT(ShowEffectDlg) // NOTE: the ClassWizard will add member initialization here m_pbmp=NULL; m_pImage=NULL; m_pImagebak=NULL; m_pPhoto=NULL; //}}AFX_DATA_INIT 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); //{{AFX_DATA_MAP(ShowEffectDlg) DDX_Control(pDX, IDC_LIST2, m_List2); DDX_Control(pDX, IDC_LIST1, m_List1); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(ShowEffectDlg, CDialog) //{{AFX_MSG_MAP(ShowEffectDlg) 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) //}}AFX_MSG_MAP END_MESSAGE_MAP() // ON_WM_ERASEBKGND() ///////////////////////////////////////////////////////////////////////////// // ShowEffectDlg message handlers unsigned __stdcall LoadThumbNail17(LPVOID lpParam) { try { ShowEffectDlg *pDlg=(ShowEffectDlg*)lpParam; CListCtrl *ListCtrl=&pDlg->m_List2; CImageList* pImgList=&pDlg->m_ImageListThumb2; // reset our image list for(int i=0; iGetImageCount(); i++) pImgList->Remove(i); // remove all items from list view ListCtrl->DeleteAllItems(); pImgList->SetImageCount(pDlg->m_vFileName2.size()); TCHAR path[MAX_PATH]; vector::iterator iter; // Set redraw to FALSE to avoid flickering during adding new items 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++) { // Load Image File 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; // Calculate Rect to fit to canvas 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); // Draw Image graph.DrawImage(image, desRect, 0,0,image->GetWidth(),image->GetHeight(),UnitPixel); delete image; // Attach to Bitmap and Replace image in CImageList CBitmap bitmap; HBITMAP hbmp; pBmp->GetHBITMAP(Color(255,255,255,255), &hbmp); bitmap.Attach(hbmp); pImgList->Replace(nIndex, &bitmap, NULL); delete pBmp; // Redraw only a current item for removing flickering and fast speed. ListCtrl->RedrawItems(nIndex, nIndex); // Release used DC and Object } 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; // reset our image list for(int i=0; iGetImageCount(); i++) pImgList->Remove(i); // remove all items from list view ListCtrl->DeleteAllItems(); pImgList->SetImageCount(pDlg->m_vFileName.size()); TCHAR path[MAX_PATH]; vector::iterator iter; // Set redraw to FALSE to avoid flickering during adding new items 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++) { // Load Image File 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; // Calculate Rect to fit to canvas 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); // Draw Image graph.DrawImage(image, desRect, 0,0,image->GetWidth(),image->GetHeight(),UnitPixel); delete image; // Attach to Bitmap and Replace image in CImageList CBitmap bitmap; HBITMAP hbmp; pBmp->GetHBITMAP(Color(255,255,255,255), &hbmp); bitmap.Attach(hbmp); pImgList->Replace(nIndex, &bitmap, NULL); delete pBmp; // Redraw only a current item for removing flickering and fast speed. ListCtrl->RedrawItems(nIndex, nIndex); // Release used DC and Object } 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); // CDialog::OnCancel (); // return false; } // TODO: Add extra initialization here // Jeff.m_rcscreen:屏幕尺寸; ::SetWindowPos(m_hWnd,HWND_TOP,0 ,0,g_screenwid,g_screenhei,SWP_SHOWWINDOW); m_rcscreen=CRect(0, 0, g_screenwid, g_screenhei); // Jeff.rc:临时区域; // Jeff.rc2:客户区域大小,用于放置PNG效果图; // Jeff.rc3:按钮区域; 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); // m_pbmp:最终显示PNG效果图的Bimap对象(PNG+客人相片 合二为一的结果); 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; iGetSize (); i++) { CString filePath=pArray->ElementAt (i); filePath.MakeLower(); m_vFileName.push_back(filePath); } TerminateThread(); m_hThread = (HANDLE)_beginthreadex(NULL,0, LoadThumbNail16,(LPVOID)this,0/* CREATE_SUSPENDED*/,&m_dwThreadID); m_bRunning=true; { if(m_bRunning2)return 0; CStringArray *pArray=m_pPhotopatharray; m_vFileName2.clear(); for(int i=0; iGetSize (); i++) { CString filePath=pArray->ElementAt (i); filePath.MakeLower(); m_vFileName2.push_back(filePath); } TerminateThread2(); m_hThread2 = (HANDLE)_beginthreadex(NULL,0, LoadThumbNail17,(LPVOID)this,0/* CREATE_SUSPENDED*/,&m_dwThreadID2); m_bRunning2=true; } SetTimer(1, 200, NULL); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } 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() { // TODO: Add your message handler code here 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); // device context for painting // TODO: Add your message handler code here try { if(m_pbmp) { Graphics graph2(dc.GetSafeHdc ()); graph2.DrawImage(m_pbmp,110,0); } } catch(...) { } // Do not call CDialog::OnPaint() for painting messages } BOOL ShowEffectDlg::OnEraseBkgnd(CDC* pDC) { // TODO: Add your message handler code here and/or call default 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(rcscaleGetWidth()==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 (".")); /* InputName dlg; if(dlg.DoModal ()!=IDOK) { path.Format ("%s\\效果图-%d.png", g_path7, GetFileNo2()); } else { */ 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; iGetSize (); i++) { CString filePath=pArray->ElementAt (i); filePath.MakeLower(); m_vFileName.push_back(filePath); } m_hThread = (HANDLE)_beginthreadex(NULL,0, LoadThumbNail16,(LPVOID)this,0/* CREATE_SUSPENDED*/,&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); // 删除效果图中的jpg文件; ::DeleteFile(spath); // 删除效果图中的s的jpg文件; m_effectpatharray.RemoveAt (selpos); m_List1.DeleteItem (selpos); m_effectpos=0; m_photopos=0; } void ShowEffectDlg::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default // SetCapture(); // m_startpt=point; CDialog::OnLButtonDown(nFlags, point); } void ShowEffectDlg::OnMouseMove(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default /* if(GetCapture()!=this)return; if(m_rc.Width ()>m_rcscreen.Width ()) { if(m_rc.left m_startpt.x) { int dt=min(point.x-m_startpt.x, m_rcscreen.left-m_rc.left); m_rc.left +=dt; m_rc.right +=dt; } else if(m_rc.right >m_rcscreen.right && point.xm_rcscreen.Height ()) { if(m_rc.top m_startpt.y) { int dt=min(point.y-m_startpt.y, m_rcscreen.top-m_rc.top); m_rc.top +=dt; m_rc.bottom +=dt; } else if(m_rc.bottom >m_rcscreen.bottom && point.y0) { m_fscale*=1.2; int dtx=(m_fscale*m_rcbak.Width ()-m_rc.Width ())/2.0; int dty=(m_fscale*m_rcbak.Height ()-m_rc.Height ())/2.0; m_rc.left -=dtx; m_rc.right +=dtx; m_rc.top -=dty; m_rc.bottom +=dty; } else { if(m_fscale<=1)return 1; m_fscale/=1.2; if(m_fscale<1)m_fscale=1; int dtx=(m_fscale*m_rcbak.Width ()-m_rc.Width ())/2.0; int dty=(m_fscale*m_rcbak.Height ()-m_rc.Height ())/2.0; m_rc.left -=dtx; m_rc.right +=dtx; m_rc.top -=dty; m_rc.bottom +=dty; if(m_rcbak.Height ()==m_rcscreen.Height ()) { if(m_rc.top m_rcscreen.top && m_rc.bottom > m_rcscreen.bottom ) { dtx=m_rc.top-m_rcscreen.top; m_rc.top -=dtx; m_rc.bottom -=dtx; } dtx=m_rc.Width (); m_rc.left =(m_rcscreen.Width ()-dtx)/2; m_rc.right =m_rc.left +dtx; } if(m_rcbak.Width ()==m_rcscreen.Width ()) { if(m_rc.left m_rcscreen.left && m_rc.right > m_rcscreen.right ) { dtx=m_rc.left-m_rcscreen.left; m_rc.left -=dtx; m_rc.right -=dtx; } dtx=m_rc.Height (); m_rc.top =(m_rcscreen.Height ()-dtx)/2; m_rc.bottom =m_rc.top +dtx; } } RcChange();*/ return CDialog::OnMouseWheel(nFlags, zDelta, pt); } void ShowEffectDlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult) { // TODO: Add your control notification handler code here 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) { // TODO: Add your message handler code here and/or call default KillTimer(nIDEvent); MakeEffect(); } void ShowEffectDlg::OnClickList2(NMHDR* pNMHDR, LRESULT* pResult) { // TODO: Add your control notification handler code here 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() { // Jeff.m_effectpatharray,客人原片\效果图\ 目录下的所有PNG图片;; if(m_effectpatharray.GetSize()==0)return; // m_pbmp:最终显示PNG效果图的Bimap对象(PNG+客人相片 合二为一的结果); 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; // m_pImage为显示的PNG效果图Bitmap对象;LoadImageFromBuf指定加载哪张PNG相片作为效果图显示; ::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); // m_pPhotopatharray:客人的相片; if(m_pPhotopatharray->GetSize ()) { if(m_bLoadPhoto) ::LoadImageFromBuf (&m_pPhoto, m_pPhotopatharray->ElementAt (m_photopos)); int i; for(int aa=0; aaGetWidth(),0), curpt); if(lengGetHeight()), curpt); if(lengGetWidth(),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; } // Jeff.pBmpImage2:被加载好的PNG效果相片; void ShowEffectDlg::GetRgn(Bitmap *pBmpImage2) { m_tempscale=1.0; if(pBmpImage2==NULL)return; // pBmpImage Bitmap *pBmpImage=NULL; BOOL bdelete=0; // .如果PNG效果相片长宽大于800 // Bitemap::GetWidth() 获取此图像的图像高度,以像素为单位; if(pBmpImage2->GetWidth()>800 || pBmpImage2->GetHeight()>800) { bdelete=1; CRect rc(0,0,800,800); // GetWidth()的长度与CRect的长度是不一样的单位值,需要转换适合图片的比例;(一个是图片的像素尺寸,一个DC的大小尺寸) 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 bitmapData; UINT* pixels; Rect rc(0, 0, pBmpImage->GetWidth(), pBmpImage->GetHeight() ); // 指定格式读取pBmpImage里的图片像素到bitmapData中; pBmpImage->LockBits( rc, // 数据被加载到的区域; ImageLockModeRead, // 锁定方式:读或写; PixelFormat32bppARGB, // 数据保存的格式; &bitmapData); // 存储数据的对象; // Write to the temporary buffer provided by LockBits. RGB // Scan0:一个空指针到第一扫描线的开始 pixels = (UINT*)bitmapData.Scan0; // Stride: // 一个INT值从位图区到下一个扫描线指定的字节数。这个值是负的自底向上的位图图像。 DWORD wids=bitmapData.Stride/4; // 除以4,刚好为Color::alpha \red \green \blue 四色(只有PNG才有alpha色); Color color; Color color1,color2,color3,color4,color5,color6,color7,color8; // m_rcarray数组,用于记录PNG图片里的alpha色小于200的像素点坐标; BYTE R,G,B; for(int aa=0; aa*pArray=NULL; for(int aa=0; aaabs(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(xcol) { break; } } if(colx0) { break; } if(xy0) { if(yrow) { break; } } if(rowy0) { break; } if(yAdd(col); // x坐标; pArray->Add(row); // y坐标; } } } pBmpImage->UnlockBits(&bitmapData); if(bdelete)delete pBmpImage; /* if(pBmpImage==NULL)return; BitmapData bitmapData; UINT* pixels; Rect rc(0, 0, pBmpImage->GetWidth(), pBmpImage->GetHeight() ); pBmpImage->LockBits( rc, ImageLockModeRead, PixelFormat32bppARGB, &bitmapData); // Write to the temporary buffer provided by LockBits. RGB pixels = (UINT*)bitmapData.Scan0; DWORD wids=bitmapData.Stride/4; Color color; Color color1,color2,color3,color4,color5,color6,color7,color8; BYTE R,G,B; m_rcarray1.RemoveAll (); m_rcarray2.RemoveAll (); m_rcarray3.RemoveAll (); m_rcarray4.RemoveAll (); m_rcarray5.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*pArray=NULL; if(m_rcarray1.GetSize () && pArray==NULL) { double x=m_rcarray1.ElementAt (0); double y=m_rcarray1.ElementAt (1); double dtx=col-x; double dty=row-y; dtx/=10.0;dty/=10.0; BOOL bFind=0; for(int a=0; a<10; a++) { x+=dtx; y+=dty; 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_rcarray1; } if(m_rcarray2.GetSize () && pArray==NULL) { double x=m_rcarray2.ElementAt (0); double y=m_rcarray2.ElementAt (1); double dtx=col-x;dtx/=10.0; double dty=row-y;dty/=10.0; BOOL bFind=0; for(int a=0; a<10; a++) { x+=dtx; y+=dty; 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_rcarray2; } if(m_rcarray3.GetSize () && pArray==NULL) { double x=m_rcarray3.ElementAt (0); double y=m_rcarray3.ElementAt (1); double dtx=col-x;dtx/=10.0; double dty=row-y;dty/=10.0; BOOL bFind=0; for(int a=0; a<10; a++) { x+=dtx; y+=dty; 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_rcarray3; } if(m_rcarray4.GetSize () && pArray==NULL) { double x=m_rcarray4.ElementAt (0); double y=m_rcarray4.ElementAt (1); double dtx=col-x;dtx/=10.0; double dty=row-y;dty/=10.0; BOOL bFind=0; for(int a=0; a<10; a++) { x+=dtx; y+=dty; 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_rcarray4; } if(m_rcarray5.GetSize () && pArray==NULL) { double x=m_rcarray5.ElementAt (0); double y=m_rcarray5.ElementAt (1); double dtx=col-x;dtx/=10.0; double dty=row-y;dty/=10.0; BOOL bFind=0; for(int a=0; a<10; a++) { x+=dtx; y+=dty; 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_rcarray5; } if(pArray==NULL) { if(m_rcarray1.GetSize ()==0) pArray=&m_rcarray1; else if(m_rcarray2.GetSize ()==0) pArray=&m_rcarray2; else if(m_rcarray3.GetSize ()==0) pArray=&m_rcarray3; else if(m_rcarray4.GetSize ()==0) pArray=&m_rcarray4; else if(m_rcarray5.GetSize ()==0) pArray=&m_rcarray5; else continue; } pArray->Add (col);pArray->Add (row); } } } pBmpImage->UnlockBits(&bitmapData); */ }