12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250 |
- #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_pImgFinalShow=NULL;
- m_pImgPNG=NULL;
- m_pImgPNGbake=NULL;
- m_pImgJPG=NULL;
-
- 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);
-
- DDX_Control(pDX, IDC_LIST2, m_ListJPG);
- DDX_Control(pDX, IDC_LIST1, m_ListPNG);
-
- }
- 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_ListJPG;
- CImageList* pImgList=&pDlg->m_ImageListThumb2;
-
- for(int i=0; i<pImgList->GetImageCount(); i++)
- pImgList->Remove(i);
-
- ListCtrl->DeleteAllItems();
- pImgList->SetImageCount(pDlg->m_vJPGFile.size());
- TCHAR path[MAX_PATH];
- vector<CString>::iterator iter;
-
- 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++)
- {
-
- 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(...)
- {
- }
- return true;
- }
- unsigned __stdcall LoadThumbNail16(LPVOID lpParam)
- {
- try
- {
- ShowEffectDlg *pDlg=(ShowEffectDlg*)lpParam;
- CListCtrl *ListCtrl=&pDlg->m_ListPNG;
- CImageList* pImgList=&pDlg->m_ImageListThumb;
-
- for(int i=0; i<pImgList->GetImageCount(); i++)
- pImgList->Remove(i);
-
- ListCtrl->DeleteAllItems();
- pImgList->SetImageCount(pDlg->m_vPNGFile.size());
- TCHAR path[MAX_PATH];
- vector<CString>::iterator iter;
-
- 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++)
- {
-
- 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(...)
- {
- }
- return true;
- }
- 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(_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);
- }
-
- ::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_ListPNG.MoveWindow(rc);
- rc=rc2;
- rc.left=rc.right-110;
- m_ListJPG.MoveWindow(rc);
-
- 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);
-
- 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,&m_dwThreadID);
- m_bRunning=true;
-
- {
- 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,&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_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);
-
- try
- {
- if(m_pImgFinalShow)
- {
- Graphics graph2(dc.GetSafeHdc ());
- graph2.DrawImage(m_pImgFinalShow,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;
- int i = 0;
- for( i=0; i<array.GetSize (); i++)
- {
- Bitmap *img=NULL;
-
- 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 ("."));
-
- 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,&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);
- ::DeleteFile(spath);
- m_AryPNGImgpaths.RemoveAt(selpos);
- m_ListPNG.DeleteItem(selpos);
- m_nPNGIndex=0;
- m_nJPGIndex=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_ListPNG.GetFirstSelectedItemPosition();
- if(pos==NULL)
- {
- return;
- }
- m_nPNGIndex=m_ListPNG.GetNextSelectedItem(pos);
- m_bLoadPNG=1;
- MakeEffect();
- *pResult = 0;
- }
- void ShowEffectDlg::OnTimer(UINT nIDEvent)
- {
-
- KillTimer(nIDEvent);
- MakeEffect();
- }
- void ShowEffectDlg::OnClickList2(NMHDR* pNMHDR, LRESULT* pResult)
- {
-
- 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()
- {
-
- if(m_AryPNGImgpaths.GetSize()==0)
- return;
-
- if ( m_pImgFinalShow == NULL )
- return;
- Graphics graph(m_pImgFinalShow);
-
- graph.Clear(Color(255,255,255,255));
- if(m_bLoadJPG)
- {
- if(m_pImgJPG)
- delete m_pImgJPG;
- m_pImgJPG = NULL;
- }
- if(m_bLoadPNG)
- {
- if(m_pImgPNG)
- delete m_pImgPNG;
- m_pImgPNG=NULL;
- if(m_pImgPNGbake)
- delete m_pImgPNGbake;
- m_pImgPNGbake=NULL;
-
- 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);
-
- 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),
- 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_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;
- }
- void ShowEffectDlg::GetRgn(IN Bitmap *pImgPNG)
- {
- m_tempscale=1.0;
- if(pImgPNG==NULL)return;
-
- Bitmap *pBmpImage=NULL;
- BOOL bdelete=0;
-
-
- if(pImgPNG->GetWidth()>800 || pImgPNG->GetHeight()>800)
- {
- bdelete=1;
- CRect rc(0,0,800,800);
-
- 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;
- 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;
- }
|