12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250 |
- // ShowEffectDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "ylgl.h"
- #include "ShowEffect.h"
- #include <math.h>
- #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; i<pImgList->GetImageCount(); i++)
- pImgList->Remove(i);
- // remove all items from list view
- ListCtrl->DeleteAllItems();
- pImgList->SetImageCount(pDlg->m_vJPGFile.size());
- TCHAR path[MAX_PATH];
- vector<CString>::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; i<pImgList->GetImageCount(); i++)
- pImgList->Remove(i);
- // remove all items from list view
- ListCtrl->DeleteAllItems();
- pImgList->SetImageCount(pDlg->m_vPNGFile.size());
- TCHAR path[MAX_PATH];
- vector<CString>::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; i<pArray->GetSize (); 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; i<pArray->GetSize (); 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(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;
- int i = 0;
- for( i=0; i<array.GetSize (); i++)
- {
- Bitmap *img=NULL;
- //::LoadImageFromBuf(&img, array.ElementAt(i));
- LoadImageFromBuf((Image**)&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 ("."));
- /* 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; i<pArray->GetSize (); 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_rcscreen.left && point.x>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.x<m_startpt.x)
- {
- int dt=min(m_startpt.x-point.x, m_rc.right-m_rcscreen.right);
- m_rc.left -=dt;
- m_rc.right -=dt;
- }
- }
- if(m_rc.Height ()>m_rcscreen.Height ())
- {
- if(m_rc.top <m_rcscreen.top && point.y>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.y<m_startpt.y)
- {
- int dt=min(m_startpt.y-point.y, m_rc.bottom-m_rcscreen.bottom);
- m_rc.top -=dt;
- m_rc.bottom -=dt;
- }
- }
- m_startpt=point;
- RcChange();*/
- CDialog::OnMouseMove(nFlags, point);
- }
- void ShowEffectDlg::OnLButtonUp(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- /* if(GetCapture()!=this)return;
- ReleaseCapture();*/
- CDialog::OnLButtonUp(nFlags, point);
- }
- BOOL ShowEffectDlg::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
- {
- // TODO: Add your message handler code here and/or call default
- /* if(m_pImage==NULL)return 1;
- if(zDelta>0)
- {
- 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_rcscreen.bottom -m_rc.bottom;
- m_rc.top +=dtx;
- m_rc.bottom +=dtx;
- }
- else 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_rcscreen.right -m_rc.right;
- m_rc.left +=dtx;
- m_rc.right +=dtx;
- }
- else 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(leng<leng1)
- {
- leng1=leng;
- pt1=curpt;
- }
- leng=GetLengFromPt(CPoint(m_pImgPNG->GetWidth(),0), curpt);
- if(leng<leng2)
- {
- leng2=leng;
- pt2=curpt;
- }
- leng=GetLengFromPt(CPoint(0,m_pImgPNG->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), // destination for upper-left point of original
- Point(pt2.x, pt2.y), // destination for upper-right point of original
- Point(pt3.x, pt3.y) // destination for lower-left point of original
- };
- // graph2.DrawImage(m_pPhoto, destinationPoints, 3);
- int lengx=GetLengFromPt2(pt1, pt2);
- int lengy=GetLengFromPt2(pt1, pt3);
- /* CString ss;
- ss.Format("pt1:%d,%d pt2:%d,%d leng:%d", pt1.x, pt1.y,pt2.x, pt2.y,lengx);
- AfxMessageBox(ss);
- ss.Format("pt1:%d,%d pt3:%d,%d leng:%d", pt1.x, pt1.y,pt3.x, pt3.y,lengy);
- AfxMessageBox(ss);*/
- CRect rc(0,0,m_pImgJPG->GetWidth(),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<RCARRARCOUNT; aa++)
- m_rcarray[aa].RemoveAll(); // Jeff.清空以前的;
- for( INT row = 0; row < rc.Height; ++row)
- {
- for(INT col = 0; col < rc.Width-1; ++col)
- {
- // 将第一行取4个点填充color对象;
- color.SetValue(pixels[row * wids + col]);
- // Color::GetA() 方法获取此Color对象的alpha分量(返回这个颜色的alpha分量)。
- 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); // x坐标;
- pArray->Add(row); // y坐标;
- }
- }
- }
- pBmpImage->UnlockBits(&bitmapData);
- if(bdelete)delete pBmpImage;
- }
|