// 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_pImgFinalShow=NULL; m_pImgPNG=NULL; m_pImgPNGbake=NULL; m_pImgJPG=NULL; //}}AFX_DATA_INIT m_nPNGIndex=0; m_nJPGIndex=0; m_fscale=1.0; m_bTerminate=false; m_bRunning=false; m_hThread = NULL; m_bTerminate2=false; m_bRunning2=false; m_hThread2 = NULL; m_bLoadPNG=1; m_bLoadJPG=1; } void ShowEffectDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(ShowEffectDlg) DDX_Control(pDX, IDC_LIST2, m_ListJPG); DDX_Control(pDX, IDC_LIST1, m_ListPNG); //}}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_ListJPG; 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_vJPGFile.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_vJPGFile.begin(); iter!=pDlg->m_vJPGFile.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_vJPGFile.begin(); iter!=pDlg->m_vJPGFile.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(...) { } return true; } unsigned __stdcall LoadThumbNail16(LPVOID lpParam) { try { ShowEffectDlg *pDlg=(ShowEffectDlg*)lpParam; CListCtrl *ListCtrl=&pDlg->m_ListPNG; 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_vPNGFile.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_vPNGFile.begin(); iter!=pDlg->m_vPNGFile.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_vPNGFile.begin(); iter!=pDlg->m_vPNGFile.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(...) { } return true; } BOOL ShowEffectDlg::OnInitDialog() { CDialog::OnInitDialog(); GetDlgItem(IDC_BUTTON2)->EnableWindow(IsHasRights2new(49)); // 获取所有PNG效果图; using namespace helper_coffs; ffsco o; o.dirs(0); o.find(LPCSTR(g_path7), LPCSTR(_T("*.png"))); ffsco::typeT coo; ffsco::typeT::iterator it; coo = o.co_file(); for (it = coo.begin(); coo.end() != it; it ++) { m_AryPNGImgpaths.Add((*it).c_str()); } if(m_AryPNGImgpaths.GetSize()==0) { AfxMessageBox(_T("您还没有安装效果图!"), MB_ICONINFORMATION); ::CreateDirectory (g_path7, NULL); } // 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_ListPNG.MoveWindow(rc); rc=rc2; rc.left=rc.right-110; m_ListJPG.MoveWindow(rc); // m_pbmp:最终显示PNG效果图的Bimap对象(PNG+客人相片 合二为一的结果); rc=rc2; rc.left +=110; rc.right -=110; m_pImgFinalShow = new Bitmap(rc.Width (), rc.Height (), PixelFormat24bppRGB ); m_ImageListThumb.Create(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, ILC_COLOR24, 0, 1); m_ListPNG.SetImageList(&m_ImageListThumb, LVSIL_NORMAL); m_ImageListThumb2.Create(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, ILC_COLOR24, 0, 1); m_ListJPG.SetImageList(&m_ImageListThumb2, LVSIL_NORMAL); // 加载PGN效果图到List列表中; if(m_bRunning)return 0; CStringArray *pArray = &m_AryPNGImgpaths; m_vPNGFile.clear(); for(int i=0; iGetSize (); i++) { CString filePath=pArray->ElementAt (i); filePath.MakeLower(); m_vPNGFile.push_back(filePath); } TerminateThread(); m_hThread = (HANDLE)_beginthreadex(NULL,0, LoadThumbNail16,(LPVOID)this,0/* CREATE_SUSPENDED*/,&m_dwThreadID); m_bRunning=true; // 加载选片界面的相片到List列表中; { if(m_bRunning2)return 0; CStringArray *pArray=m_pPhotopatharray; m_vJPGFile.clear(); for(int i=0; iGetSize (); i++) { CString filePath=pArray->ElementAt (i); filePath.MakeLower(); m_vJPGFile.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_pImgFinalShow) delete m_pImgFinalShow; m_pImgFinalShow=NULL; if(m_pImgPNG) delete m_pImgPNG; m_pImgPNG=NULL; if(m_pImgPNGbake) delete m_pImgPNGbake; m_pImgPNGbake=NULL; if(m_pImgJPG) delete m_pImgJPG; m_pImgJPG=NULL; CDialog::OnDestroy(); } void ShowEffectDlg::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here try { if(m_pImgFinalShow) { Graphics graph2(dc.GetSafeHdc ()); graph2.DrawImage(m_pImgFinalShow,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_nPNGIndex=0; m_nJPGIndex=0; m_AryPNGImgpaths.RemoveAll (); using namespace helper_coffs; ffsco o; o.dirs(0); o.find(LPCSTR(g_path7), LPCSTR(_T("*.png"))); ffsco::typeT coo; ffsco::typeT::iterator it; coo = o.co_file(); for (it = coo.begin(); coo.end() != it; it ++) { m_AryPNGImgpaths.Add((*it).c_str()); } if(m_AryPNGImgpaths.GetSize()==0) { AfxMessageBox(_T("您还没有安装效果图!"), MB_ICONINFORMATION); ::CreateDirectory (g_path7, NULL); } TerminateThread(); CStringArray *pArray=&m_AryPNGImgpaths; m_vPNGFile.clear(); for( i=0; iGetSize (); i++) { CString filePath=pArray->ElementAt (i); filePath.MakeLower(); m_vPNGFile.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_ListPNG.GetFirstSelectedItemPosition(); if(pos==NULL) { return; } int selpos=m_ListPNG.GetNextSelectedItem(pos); if(AfxMessageBox("确认删除吗?", MB_YESNO|MB_ICONINFORMATION)!=IDYES)return; CString str=m_AryPNGImgpaths.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_AryPNGImgpaths.RemoveAt(selpos); m_ListPNG.DeleteItem(selpos); m_nPNGIndex=0; m_nJPGIndex=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_ListPNG.GetFirstSelectedItemPosition(); if(pos==NULL) { return; } m_nPNGIndex=m_ListPNG.GetNextSelectedItem(pos); m_bLoadPNG=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_ListJPG.GetFirstSelectedItemPosition(); if(pos==NULL) { return; } m_nJPGIndex=m_ListJPG.GetNextSelectedItem(pos); m_bLoadJPG=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((float)(pt1.x-pt2.x)*(pt1.x-pt2.x)+(pt1.y-pt2.y)*(pt1.y-pt2.y)); } void ShowEffectDlg::MakeEffect() { // Jeff.m_AryPNGImgpaths,客人原片\效果图\ 目录下的所有PNG图片;; if(m_AryPNGImgpaths.GetSize()==0) return; // m_pbmp:最终显示PNG效果图的Bimap对象(PNG+客人相片 合二为一的结果); if ( m_pImgFinalShow == NULL ) return; Graphics graph(m_pImgFinalShow); // 将对象区域全部以透明色填充; graph.Clear(Color(255,255,255,255)); if(m_bLoadJPG) {// 加载新的JPG相片; if(m_pImgJPG) delete m_pImgJPG; m_pImgJPG = NULL; } if(m_bLoadPNG) {// 加载新的PNG效果图; if(m_pImgPNG) delete m_pImgPNG; m_pImgPNG=NULL; if(m_pImgPNGbake) delete m_pImgPNGbake; m_pImgPNGbake=NULL; // m_pImage为显示的PNG效果图Bitmap对象;LoadImageFromBuf指定加载哪张PNG相片作为效果图显示; LoadImageFromBuf((Image**)&m_pImgPNG, m_AryPNGImgpaths.ElementAt(m_nPNGIndex)); if(m_pPhotopatharray->GetSize()) { GetRgn(m_pImgPNG); } m_pImgPNGbake = m_pImgPNG->Clone(0,0,m_pImgPNG->GetWidth(),m_pImgPNG->GetHeight(),PixelFormat32bppARGB ); } int width,height; width=m_pImgPNG->GetWidth(); height=m_pImgPNG->GetHeight(); if(width==0 || height==0) return; InitRc(m_pImgPNG); CPoint pt1,pt2,pt3; int leng1,leng2,leng3; CPoint curpt; int leng; Graphics graph2(m_pImgPNG); // m_pPhotopatharray:客人的相片; if(m_pPhotopatharray->GetSize()) { if(m_bLoadJPG) {// 加载顾客相片; LoadImageFromBuf(&m_pImgJPG, m_pPhotopatharray->ElementAt(m_nJPGIndex)); } 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(lengGetWidth(),0), curpt); if(lengGetHeight()), curpt); if(lengGetWidth(),m_pImgJPG->GetHeight()); RectFitDes(lengx,lengy,rc); graph2.DrawImage( m_pImgJPG, destinationPoints, 3, rc.left, rc.top, rc.Width(), rc.Height(), UnitPixel, NULL, NULL, NULL); } } /////// graph2.DrawImage(m_pImgPNGbake, 0, 0); } Rect destinationRect( m_rc.left , m_rc.top , m_rc.Width (), m_rc.Height () ); graph.DrawImage(m_pImgPNG, destinationRect, 0,0,width,height,UnitPixel); CRect rc; GetClientRect(rc); rc.left +=110; rc.right -=110; InvalidateRect(rc); m_bLoadPNG=0; m_bLoadJPG=0; } // Jeff.pBmpImage2:被加载好的PNG效果相片; // 获取PNG效果图的透明区域; /************************************************************************/ /* 函数:GetRgn 描述:获取指定Bitmap对象所表示的图像的透明区域; 参数: pImgPNG[IN] 要获取透明区域的Bitmap对象指针; 返回: 注意: */ /************************************************************************/ void ShowEffectDlg::GetRgn(IN Bitmap *pImgPNG) { m_tempscale=1.0; if(pImgPNG==NULL)return; // pBmpImage Bitmap *pBmpImage=NULL; BOOL bdelete=0; // .如果PNG效果相片长宽大于800 // Bitemap::GetWidth() 获取此图像的图像高度,以像素为单位; if(pImgPNG->GetWidth()>800 || pImgPNG->GetHeight()>800) { bdelete=1; CRect rc(0,0,800,800); // GetWidth()的长度与CRect的长度是不一样的单位值,需要转换适合图片的比例;(一个是图片的像素尺寸,一个DC的大小尺寸) RectFitDes(pImgPNG->GetWidth(), pImgPNG->GetHeight(), rc); // 在适合图片长宽比例的显示设备中重新装载图片; pBmpImage=new Bitmap(rc.Width (), rc.Height (), PixelFormat32bppARGB ); Graphics graphic(pBmpImage); graphic.Clear(Color(0,0,0,0)); graphic.DrawImage(pImgPNG, 0,0,pBmpImage->GetWidth(), pBmpImage->GetHeight() ); m_tempscale=(float)pImgPNG->GetWidth()/(float)pBmpImage->GetWidth(); } else pBmpImage=pImgPNG; // 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; }