123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544 |
- // DlgRenderings.cpp : 实现文件
- //
- #include "stdafx.h"
- #include "Renderings.h"
- #include "DlgRenderings.h"
- #include <Shlwapi.h>
- #include "IMGCommon.h"
- ThreadSection CDlgRenderings::m_cs;
- CRect CDlgRenderings::m_rcWndClient;
- vector<STImageAlpha> CDlgRenderings::m_vtPngAlphaInfo;
- unsigned __stdcall LoadJPGThumbNail(LPVOID lpParam);
- unsigned __stdcall LoadPNGThumbNail(LPVOID lpParam);
- // CDlgRenderings 对话框
- IMPLEMENT_DYNAMIC(CDlgRenderings, CDialog)
- CDlgRenderings::CDlgRenderings(CWnd* pParent /*=NULL*/)
- : CDialog(CDlgRenderings::IDD, pParent)
- {
- m_pbmp = NULL;
- m_pPNGImage = NULL;
- m_pImagebak = NULL;
- m_pJPGImage = NULL;
- //}}AFX_DATA_INIT
- m_nSelectPNGPosition = -1;
- m_nSelectJPGPosition = -1;
- m_fscale = 1.0;
- m_bTerminate = false;
- m_bRunning = false;
- m_hThread = NULL;
- m_bTerminate2 = false;
- m_bRunning2 = false;
- m_hThread2 = NULL;
- m_bLoadEffectPNGImg = 1;
- m_bLoadPhotoJPGImg = 1;
- m_bMousePress = FALSE;
- m_nCurAlphaIndex = 0;
- }
- CDlgRenderings::~CDlgRenderings()
- {
- }
- void CDlgRenderings::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- DDX_Control(pDX, LIST_PNG, m_ListPNG);
- DDX_Control(pDX, LIST_JPG, m_ListJPG);
- }
- BEGIN_MESSAGE_MAP(CDlgRenderings, CDialog)
- ON_WM_PAINT()
- ON_WM_ERASEBKGND()
- ON_NOTIFY(NM_CLICK, LIST_PNG, &CDlgRenderings::OnNMClickList1)
- ON_NOTIFY(NM_CLICK, LIST_JPG, &CDlgRenderings::OnNMClickList2)
- ON_WM_DESTROY()
- ON_BN_CLICKED(Btn_ADD, &CDlgRenderings::OnBnClickedAdd)
- ON_BN_CLICKED(Btn_Delete, &CDlgRenderings::OnBnClickedDelete)
- ON_WM_LBUTTONUP()
- ON_WM_LBUTTONDOWN()
- ON_WM_MOUSEMOVE()
- ON_WM_MOUSEWHEEL()
- END_MESSAGE_MAP()
- // CDlgRenderings 消息处理程序
- BOOL CDlgRenderings::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // TODO: 在此添加额外的初始化
- m_pPhotopatharray = &g_AryCustomerImage;
- if (m_pPhotopatharray->GetSize() == 0)
- {
- AfxMessageBox(_T("没有加载到任何相片"));
- }
- if (PathFileExists(g_strPathOfPNG))
- {
- TString str;
- int nIndex = 0;
- STR_VEC vtfiles;
- filehelpImpl ffhelp;
- ffhelp.getfiles_findout_subfolder(g_strPathOfPNG, "*.png", &vtfiles);
- for (STR_VEC::iterator it = vtfiles.begin(); it != vtfiles.end(); it++)
- {
- str = it->c_str();
- nIndex = it->find_last_of(_T('\\'));
- if ( nIndex != TString::npos )
- {
- // 是否是s,或m文件;
- if (str.substr(nIndex + 1, -1).at(0) == _T('s') || str.substr(nIndex + 1, -1).at(0) == _T('m'))
- {
- str.erase(nIndex + 1, 1);
- if ( PathFileExists(str.c_str()) )
- continue;
- }
- m_AryEffectPNGImg.Add(it->c_str());
- }
- }
- }
- size_t nSize = m_AryEffectPNGImg.GetSize();
- if (nSize == 0)
- {
- AfxMessageBox(_T("您还没有安装效果图!"), MB_ICONINFORMATION);
- ::CreateDirectory(g_strPathOfPNG, NULL);
- }
- // TODO: Add extra initialization here
- // m_rcscreen:屏幕尺寸;
- #ifdef _DEBUG
- ::SetWindowPos(m_hWnd, NULL, 0, 0, g_nScreenWidth, g_nScreenHeight, SWP_SHOWWINDOW);
- #else
- ::SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, g_nScreenWidth, g_nScreenHeight, SWP_SHOWWINDOW);
- #endif
- m_rcscreen = CRect(0, 0, g_nScreenWidth, g_nScreenHeight);
- GetClientRect(m_rcWndClient);
- HANDLE hThread = CreateThread(NULL, 0, Thread_GetAllPNGInfo, NULL, 0, NULL);
- CloseHandle(hThread);
- // rc:临时区域;
- // rc2:客户区域大小,用于放置PNG效果图;
- // rc3:按钮区域;
- CRect rc, rc2, rc3;
- GetClientRect(rc2);
- GetDlgItem(Btn_Delete)->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+客人相片 合二为一的结果);
- m_rcBackground = rc2;
- m_rcBackground.left += 110;
- m_rcBackground.right -= 110;
- m_pbmp = new Gdiplus::Bitmap(m_rcBackground.Width(), m_rcBackground.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);
- ::SetWindowLong(m_ListJPG.GetSafeHwnd(), GWL_STYLE, WS_CHILD | WS_VISIBLE | WS_HSCROLL);
- ::SetWindowLong(m_ListPNG.GetSafeHwnd(), GWL_STYLE, WS_CHILD | WS_VISIBLE | WS_HSCROLL);
- if (m_bRunning)
- return 0;
- CStringArray *pArray = &m_AryEffectPNGImg;
- m_vPNGFile.RemoveAll();
- for (int i = 0; i < pArray->GetSize(); i++)
- {
- CString filePath = pArray->ElementAt(i);
- filePath.MakeLower();
- m_vPNGFile.Add(filePath);
- }
- TerminateThread();
- m_hThread = (HANDLE)_beginthreadex(NULL, 0, LoadJPGThumbNail, (LPVOID)this, 0/* CREATE_SUSPENDED*/, &m_dwThreadID);
- m_bRunning = true;
- if (m_bRunning2)
- return 0;
- pArray = NULL;
- pArray = m_pPhotopatharray;
- m_vJPGFile.RemoveAll();
- for (int i = 0; i < pArray->GetSize(); i++)
- {
- CString filePath = pArray->ElementAt(i);
- filePath.MakeLower();
- m_vJPGFile.Add(filePath);
- }
- TerminateThread2();
- m_hThread2 = (HANDLE)_beginthreadex(NULL, 0, LoadPNGThumbNail, (LPVOID)this, 0/* CREATE_SUSPENDED*/, &m_dwThreadID2);
- m_bRunning2 = true;
- DWORD dwSize = m_AryEffectPNGImg.GetSize();
- //LoadPNGImageSuper(0);
- return TRUE; // return TRUE unless you set the focus to a control
- // 异常: OCX 属性页应返回 FALSE
- }
- // 如果向对话框添加最小化按钮,则需要下面的代码
- // 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
- // 这将由框架自动完成。
- void CDlgRenderings::OnPaint()
- {
- CPaintDC dc(this); // 用于绘制的设备上下文
- try
- {
- if (m_pbmp)
- {
- Graphics graphics(dc.GetSafeHdc());
- graphics.DrawImage(m_pbmp, m_rcBackground.left, m_rcBackground.top);
- }
- }
- catch (...)
- {
- }
- //CDialog::OnPaint();
- }
- BOOL CDlgRenderings::OnEraseBkgnd(CDC* pDC)
- {
- // TODO: 在此添加消息处理程序代码和/或调用默认值
- static BOOL bErase = FALSE;
- if (!bErase)
- {//第一次时,要让窗口完全绘制出来,不然会有其他窗口背景;
- bErase = TRUE;
- return CDialog::OnEraseBkgnd(pDC);
- }
- return TRUE;
- }
- void CDlgRenderings::OnNMClickList1(NMHDR *pNMHDR, LRESULT *pResult) // 单击PNG列表图标;
- {
- LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
- POSITION pos = m_ListPNG.GetFirstSelectedItemPosition();
- if (pos == NULL)
- return;
- m_nCurAlphaIndex = 0;
- m_nSelectJPGPosition = -1;
- m_bLoadEffectPNGImg = LoadPNGImageSuper(m_ListPNG.GetNextSelectedItem(pos));
- // 清空Offsset图片内容;
- for (vector<STOffSetInfo>::iterator it = m_vtOffSetInfo.begin(); it != m_vtOffSetInfo.end(); it++ )
- {
- if (it->pImage)
- {
- it->fScale = 1.0;
- it->nXOffSet = 0;
- it->nYOffSet = 0;
- delete it->pImage;
- it->pImage = NULL;
- }
- }
- *pResult = 0;
- }
- void CDlgRenderings::OnNMClickList2(NMHDR *pNMHDR, LRESULT *pResult) // 单击JPG列表图标;
- {
- LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
- POSITION pos = m_ListJPG.GetFirstSelectedItemPosition();
- if (pos == NULL)
- return;
- static int nLastPosition = -1;
- nLastPosition = m_nSelectJPGPosition;
- m_nSelectJPGPosition = m_ListJPG.GetNextSelectedItem(pos);
- static int nLastAlphaPosition = -1;
- if (nLastAlphaPosition == m_nCurAlphaIndex && nLastPosition == m_nSelectJPGPosition)
- {// 前后两次选中透明区域相同,且前后两次选中的JPG也相同,不执行任何操作,直接返回;
- return;
- }
- nLastAlphaPosition = m_nCurAlphaIndex;
- nLastPosition = m_nSelectJPGPosition;
- m_bLoadPhotoJPGImg = TRUE;
- Image *pJpgImage = NULL;
- CString strText = m_pPhotopatharray->ElementAt(m_nSelectJPGPosition);
- IMGCommon::LoadImgFromFile((Image**)&pJpgImage, strText);
- if (pJpgImage)
- {// 加载JPG成功,则要清除上一次透明区域的JPG图片对象;
- STOffSetInfo *pOffSet = NULL;
- if ( m_vtOffSetInfo.size() == 0 )
- {
- STOffSetInfo OffSet;
- OffSet.nIndexOfAlpha = m_nCurAlphaIndex;
- OffSet.nXOffSet = 0;
- OffSet.nYOffSet = 0;
- OffSet.pImage = pJpgImage;
- m_vtOffSetInfo.push_back(OffSet);
- LoadJPGImageSuper(&m_vtOffSetInfo[0]);
- return;
- }
- for (vector<STOffSetInfo>::iterator it = m_vtOffSetInfo.begin(); it != m_vtOffSetInfo.end(); it++)
- {
- if (it->nIndexOfAlpha == m_nCurAlphaIndex)
- {
- it->nXOffSet = 0;
- it->nYOffSet = 0;
- if (it->pImage)
- {
- delete it->pImage;
- it->pImage = NULL;
- }
- it->fScale = 1.0;
- it->pImage = pJpgImage;
- pOffSet = (STOffSetInfo *)(&*it);
- }
- }
- if (pOffSet)
- LoadJPGImageSuper(pOffSet);
- }
- *pResult = 0;
- }
- #ifdef __UN_USE__
- void CDlgRenderings::MakeEffect()
- {
- // Jeff.m_AryEffectPNGImg,客人原片\效果图\ 目录下的所有PNG图片;;
- if (m_AryEffectPNGImg.GetSize() == 0)
- return;
- // m_pbmp:最终显示PNG效果图的Bimap对象(PNG+客人相片 合二为一的结果);
- Graphics graph(m_pbmp);
- // 将对象区域全部以透明色填充;
- graph.Clear(Color(255, 255, 255, 255));
- if (m_bLoadPhotoJPGImg)
- {
- if (m_pJPGImage)
- delete m_pJPGImage;
- m_pJPGImage = NULL;
- }
- if (m_bLoadEffectPNGImg)
- {
- if (m_pPNGImage)
- delete m_pPNGImage;
- m_pPNGImage = NULL;
- if (m_pImagebak)
- delete m_pImagebak;
- m_pImagebak = NULL;
- // m_pPNGImage为显示的PNG效果图Bitmap对象;LoadImageFromBuf指定加载哪张PNG相片作为效果图显示;
- IMGCommon::LoadImgFromFile((Image**)&m_pPNGImage, m_AryEffectPNGImg.ElementAt(m_nSelectPNGPosition));
- if (m_pPhotopatharray->GetSize())
- {
- // 如果Jpg存在,计算png的透明区域;
- GetRgn(m_pPNGImage);
- }
- m_pImagebak = m_pPNGImage->Clone(0, 0, m_pPNGImage->GetWidth(), m_pPNGImage->GetHeight(), PixelFormat32bppARGB);
- }
- int width, height;
- width = m_pPNGImage->GetWidth();
- height = m_pPNGImage->GetHeight();
- if (width == 0 || height == 0)return;
- InitRc(m_pPNGImage);
- CPoint pt1, pt2, pt3;
- int leng1, leng2, leng3;
- CPoint curpt;
- int leng;
- Graphics graph2(m_pPNGImage);
- // m_pPhotopatharray:客人的相片;
- if (m_pPhotopatharray->GetSize())
- {
- if (m_bLoadPhotoJPGImg)
- {
- CString strText = m_pPhotopatharray->ElementAt(m_nSelectJPGPosition);
- IMGCommon::LoadImgFromFile((Image**)&m_pJPGImage, strText);
- }
- if (m_pJPGImage == NULL)
- {
- return;
- }
- int i;
- for (int nAlphaIndex = 0; nAlphaIndex < RCARRARCOUNT; nAlphaIndex++)
- {
- leng1 = leng2 = leng3 = 10000000;
- for (i = 0; i < m_rcarray[nAlphaIndex].GetSize(); i += 2)
- {
- curpt.x = m_rcarray[nAlphaIndex].ElementAt(i);
- curpt.y = m_rcarray[nAlphaIndex].ElementAt(i + 1);
- leng = GetLengFromPt(CPoint(0, 0), curpt); // 计算出斜边平方值,也就是两点间的距离;
- if (leng < leng1)
- {
- leng1 = leng;
- pt1 = curpt;
- }
- leng = GetLengFromPt(CPoint(m_pPNGImage->GetWidth(), 0), curpt);
- if (leng < leng2)
- {
- leng2 = leng;
- pt2 = curpt;
- }
- leng = GetLengFromPt(CPoint(0, m_pPNGImage->GetHeight()), curpt);
- if (leng < leng3)
- {
- leng3 = leng;
- pt3 = curpt;
- }
- }
- if (m_rcarray[nAlphaIndex].GetSize())
- {
- // m_tempscale为缩放值,点坐标要缩放;
- 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_pJPGImage, destinationPoints, 3);
- // 计算出每个透明区域的宽、高;
- int lengx = GetLengFromPt2(pt1, pt2);
- int lengy = GetLengFromPt2(pt1, pt3);
- CRect rc(0, 0, m_pJPGImage->GetWidth(), m_pJPGImage->GetHeight());
- RectFitDes(lengx, lengy, rc);
- graph2.DrawImage(
- m_pJPGImage,
- 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_pPNGImage, destinationRect, 0, 0, width, height, UnitPixel);
- CRect rc;
- GetClientRect(rc);
- rc.left += 110;
- rc.right -= 110;
- InvalidateRect(rc);
- m_bLoadEffectPNGImg = FALSE;
- m_bLoadPhotoJPGImg = FALSE;
- }
- /************************************************************************/
- /* 函数:GetRgn[4/9/2017 Jeff];
- /* 描述:获取指定PNG图像的透明区域;
- /* 参数:;
- /* [IN] pBmpImage2:PNG图像对象;
- /* [OUT] :;
- /* [IN/OUT] :;
- /* 返回:void;
- /* 注意:RGN和RECT的区别在于,RECT的矩形,RGN是任意形状;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- void CDlgRenderings::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()> m_rcBackground.Width() || pBmpImage2->GetHeight()> m_rcBackground.Height())
- if (pBmpImage2->GetWidth() > 800 || pBmpImage2->GetHeight() > 800)
- {
- bdelete = 1;
- //CRect rc(0,0,m_rcBackground.Width(),m_rcBackground.Height());
- CRect rc(0, 0, 800, 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是指图像每一行需要占用的字节数。根据BMP格式的标准,Stride一定要是4的倍数。
- // Stride:
- // 一个INT值从位图区到下一个扫描线指定的字节数。这个值是负的自底向上的位图图像。
- DWORD wids = bitmapData.Stride / 4; // 除以4,刚好为Color::alpha \red \green \blue 四色(只有PNG才有alpha色);
- // 像素(x,y)的颜色;
- Color color;
- // 像素(x,y)四周8个方向的像素颜色:
- // (x-1,y-1);
- // (x-0,y-1);
- // (x+1,y-1);
- // (x-1,y-0);
- // (x+1,y-0);
- // (x-1,y+1);
- // (x-0,y+1);
- // (x+1,y+1);
- Color color1, color2, color3, color4, color5, color6, color7, color8;
- // m_rcarray数组,用于记录PNG图片里的alpha色小于200的像素点坐标;
- BYTE R, G, B;
- for (int nAlphaIndex = 0; nAlphaIndex < RCARRARCOUNT; nAlphaIndex++)
- m_rcarray[nAlphaIndex].RemoveAll(); // Jeff.清空以前的;
- for (INT row = 0; row < rc.Height; ++row)
- {
- for (INT col = 0; col < rc.Width - 1; ++col)
- {
- // 将PNG图片当前像素(col,row)点的颜色值填充到color对象;
- color.SetValue(pixels[row * wids + col]);
- // Color::GetA() 方法获取此Color对象的alpha分量(返回这个颜色的alpha分量)。
- BYTE byalpha = color.GetA();
- if (byalpha < 200)
- {
- CArray<int, int>*pArray = NULL;
- for (int nAlphaIndex = 0; nAlphaIndex < RCARRARCOUNT; nAlphaIndex++)
- {
- if (m_rcarray[nAlphaIndex].GetSize() && pArray == NULL)
- {
- // 从区域nAlphaIndex的第一个点开始,判断当前像素点(col,row)是否属于该区域的连续同色;
- double x = m_rcarray[nAlphaIndex].ElementAt(0);
- double y = m_rcarray[nAlphaIndex].ElementAt(1);
- // x0,y0作为原点;
- int x0 = (int)x;
- int y0 = (int)y;
- // col、row为当前点;
- // x、y为对照点;
- double dtx = col - x;
- double dty = row - y;
- // 求得tan或cot值;
- if (abs(dtx) > abs(dty))
- {// 左右象限(3、4、7、8);
- if (dty)
- {// 在原点下方(4、7);
- dtx /= abs(dty); // cot;
- dty /= abs(dty); // 1;
- }
- else
- {// 在原点上方(3、8);
- if (dtx > 0)
- {//在原点右方(3);
- dtx = 1;
- }
- else if (dtx < 0)
- {//在原点左方(8);
- dtx = -1;
- }
- }
- }
- else
- {// 上下象限(1、2、5、6);
- if (dtx)
- {//在原点右方(2、5);
- dty /= abs(dtx); // tan;
- dtx /= abs(dtx); // 1;
- }
- else
- {//在原点左方(1、6);
- if (dty > 0)
- {//在原点下方(6);
- dty = 1;
- }
- else if (dtx < 0)
- {//在原点上方(1);
- dty = -1;
- }
- }
- }
- // 此时dtx或dty已为tan或cot值,当tan或cot的值大于3时,角度是72或18度左右;
- 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 = FALSE;
- 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 || x > col)
- {// 新点不在原点和像素点x坐标之间;
- break;
- }
- }
- if (col < x0)
- {//在原点左侧;
- if (x > x0 || x < col)
- {// 新点不在原点和像素点x坐标之间;
- break;
- }
- }
- if (row > y0)
- {//在原点下方;
- if (y < y0 || y > row)
- {// 新点不在原点和像素点y坐标之间;
- break;
- }
- }
- if (row < y0)
- {//在原点上方;
- if (y > y0 || y < row)
- {// 新点不在原点和像素点y坐标之间;
- 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)
- {// 当前像素4周8个方向的像素点颜色与当前像素一致,表明为连续区域;
- bFind = 1;
- break;
- }
- }
- }
- if (!bFind)
- {// 不是连续点,则开一个数组保存这块新的区域;
- pArray = &(m_rcarray[nAlphaIndex]);
- }
- }
- }
- 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;
- }
- #endif
- BOOL CDlgRenderings::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 CDlgRenderings::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;
- }
- #ifdef __UN_USE__
- void CDlgRenderings::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 (...)
- {
- }
- }
- #endif
- unsigned __stdcall LoadJPGThumbNail(LPVOID lpParam)
- {
- try
- {
- CDlgRenderings *pDlg = (CDlgRenderings*)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();
- if (pDlg->m_vJPGFile.GetSize() == 0) // 没有效果图时,线程不处理其他;
- {
- return 0;
- }
- pImgList->SetImageCount(pDlg->m_vJPGFile.GetSize());
- 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_vFileName2.begin(); iter!=pDlg->m_vFileName2.end() && pDlg->m_bTerminate2!=true; iter++, nIndex++)
- for (INT i = 0; i < pDlg->m_vJPGFile.GetSize(); i++, nIndex++)
- {
- //str=*iter;
- str = pDlg->m_vJPGFile.ElementAt(i);
- 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++)
- for (INT i = 0; i < pDlg->m_vJPGFile.GetSize(); i++, nIndex++)
- {
- // Load Image File
- Image *image = NULL;
- Bitmap *pBmp = NULL;
- str = pDlg->m_vJPGFile.ElementAt(i);
- spath = str.Left(str.ReverseFind('\\') + 1);
- spath += "s";
- spath += str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
- if (PathFileExists(spath))
- IMGCommon::LoadImgFromFile(&image, spath);
- else
- IMGCommon::LoadImgFromFile(&image, str);
- if (image == NULL)
- {
- continue;
- }
- int orientation = IMGCommon::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 0;
- }
- unsigned __stdcall LoadPNGThumbNail(LPVOID lpParam)
- {
- try
- {
- CDlgRenderings *pDlg = (CDlgRenderings*)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();
- if (pDlg->m_vJPGFile.GetSize() == 0 || pDlg->m_vPNGFile.GetSize() == 0) // 没有相片,线程不处理其他;
- {
- return 0;
- }
- pImgList->SetImageCount(pDlg->m_vPNGFile.GetSize());
- 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 (INT i = 0; i < pDlg->m_vPNGFile.GetSize(); i++, nIndex++)
- {
- str = pDlg->m_vPNGFile.ElementAt(i);
- 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 (INT i = 0; i < pDlg->m_vPNGFile.GetSize(); i++, nIndex++)
- {
- // Load Image File
- Image *image = NULL;
- Bitmap *pBmp = NULL;
- //str=*iter;
- str = pDlg->m_vPNGFile.ElementAt(i);
- spath = str.Left(str.ReverseFind('\\') + 1);
- spath += "s";
- spath += str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
- spath.Replace("png", "jpg");
- if (PathFileExists(spath))
- {
- IMGCommon::LoadImgFromFile(&image, spath);
- }
- else if (PathFileExists(str))
- {
- IMGCommon::LoadImgFromFile(&image, str);
- }
- else
- {
- AfxMessageBox("没有相片");
- continue;
- }
- int orientation = IMGCommon::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;
- pDlg->m_nSelectPNGPosition = 0;
- pDlg->LoadPNGImageSuper(0);
- _endthreadex(0);
- return 0;
- }
- catch (...)
- {
- }
- return 0;
- }
- void CDlgRenderings::OnDestroy()
- {
- TerminateThread2();
- TerminateThread();
- if (m_pbmp)
- delete m_pbmp;
- m_pbmp = NULL;
- if (m_pPNGImage)
- delete m_pPNGImage;
- m_pPNGImage = NULL;
- if (m_pImagebak)
- delete m_pImagebak;
- m_pImagebak = NULL;
- if (m_pJPGImage)
- delete m_pJPGImage;
- m_pJPGImage = NULL;
- CDialog::OnDestroy();
- // TODO: 在此处添加消息处理程序代码
- }
- void CDlgRenderings::OnBnClickedAdd()
- {
- AfxMessageBox(_T("制作方法:\r\n1.图片格式为透明PNG格式.\r\n2.显示客照的位置为透明."), MB_ICONINFORMATION);
- CFileDialog fdlg(true, NULL, _T("openfile"), OFN_ALLOWMULTISELECT, _T("png文件(*.png)|*.png||"));
- TCHAR szBuffer[60000] = { 0 };
- fdlg.m_ofn.lpstrFile = szBuffer;
- fdlg.m_ofn.nMaxFile = 60000;
- if (fdlg.DoModal() != IDOK)
- {
- return;
- }
- POSITION pos = fdlg.GetStartPosition();
- CStringArray array;
- while (pos != NULL)
- {
- array.Add(fdlg.GetNextPathName(pos));
- }
- if (array.GetSize() == 0)
- return;
- for ( int i = 0; i < array.GetSize(); i++ )
- {
- AddNewImageItem(array.ElementAt(i));
- }
- }
- void CDlgRenderings::OnBnClickedDelete()
- {
- // TODO: 在此添加控件通知处理程序代码
- POSITION pos;
- pos = m_ListPNG.GetFirstSelectedItemPosition();
- if (pos == NULL)
- {
- return;
- }
- int selpos = m_ListPNG.GetNextSelectedItem(pos);
- if (AfxMessageBox(_T("确认删除吗?"), MB_YESNO | MB_ICONINFORMATION) != IDYES)
- return;
- CString str = m_AryEffectPNGImg.ElementAt(selpos);
- for (vector<STImageAlpha>::iterator it = m_vtPngAlphaInfo.begin(); it != m_vtPngAlphaInfo.end(); it++ )
- {
- if (str.CompareNoCase(it->PNGFileName) == 0)
- {
- m_vtPngAlphaInfo.erase(it);
- break;
- }
- }
- 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_AryEffectPNGImg.RemoveAt(selpos);
- m_ListPNG.DeleteItem(selpos);
- m_nSelectPNGPosition = 0;
- m_nSelectJPGPosition = 0;
- }
- void CDlgRenderings::OnLButtonUp(UINT nFlags, CPoint point)
- {
- // 鼠标放开;
- m_bMousePress = FALSE;
- // 判断鼠标坐标点是否在透明区域内,在返回透明区域索引;
- m_nCurAlphaIndex = IsPointInAlphaRect(point);
- if (m_nCurAlphaIndex >= 0)
- {// 鼠标点在透明区域内;
- // 遍历JPG透明集合,查看该透明区域是否有加载JPG;
- BOOL bExist = FALSE;
- for (vector<STOffSetInfo>::iterator it = m_vtOffSetInfo.begin(); it != m_vtOffSetInfo.end(); it++)
- {
- if (it->nIndexOfAlpha == m_nCurAlphaIndex)
- {
- bExist = TRUE;
- break;
- }
- }
- if (!bExist)
- {// 没有加载,新建元素;
- STOffSetInfo OffSet;
- OffSet.nIndexOfAlpha = m_nCurAlphaIndex;
- OffSet.nXOffSet = 0;
- OffSet.nYOffSet = 0;
- m_vtOffSetInfo.push_back(OffSet);
- }
- }
- // 为上一次选中的透明区域画白色边框;
- DrawAlphaEdge(m_ptLastRectangle, true);
- // 为当前选中的透明区域画红色边框
- DrawAlphaEdge(point);
- CDialog::OnLButtonUp(nFlags, point);
- }
- void CDlgRenderings::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // 鼠标放开;
- m_bMousePress = TRUE;
- // 判断点是否在透明区域内;
- CDialog::OnLButtonDown(nFlags, point);
- }
- void CDlgRenderings::OnMouseMove(UINT nFlags, CPoint point)
- {
- CRect rcList1;
- CRect rcList2;
- m_ListPNG.GetWindowRect(&rcList1);
- m_ListJPG.GetWindowRect(&rcList2);
- if ( !rcList1.PtInRect(point) || !rcList2.PtInRect(point))
- {// 如果鼠标点坐标不在list1和list2,设置客户区域获取焦点;
- SetFocus();
- }
- CDialog::OnMouseMove(nFlags, point);
- }
- #ifdef __UN_USE__
- BOOL CDlgRenderings::LoadPNGImage(IN INT nIndex)
- {
- if (m_AryEffectPNGImg.GetSize() == 0 || (nIndex != 0 && (nIndex == m_nSelectPNGPosition)))
- return FALSE;
- m_nSelectPNGPosition = nIndex;
- // m_pbmp:最终显示PNG效果图的Bimap对象(PNG+客人相片 合二为一的结果);
- Graphics graph(m_pbmp);
- // 将对象区域全部不透明白色填充;
- graph.Clear(Color(255, 255, 255, 255));
- #ifndef _DEBUG // Debug模式下删除会出错;
- if (m_pPNGImage)
- delete m_pPNGImage;
- m_pPNGImage = NULL;
- if (m_pImagebak)
- delete m_pImagebak;
- m_pImagebak = NULL;
- #endif
- // m_pPNGImage为显示的PNG效果图Bitmap对象;LoadImageFromBuf指定加载哪张PNG相片作为效果图显示;
- //LoadImageFromBuf((Image**)&m_pPNGImage, m_AryEffectPNGImg.ElementAt(nIndex));
- IMGCommon::LoadImgFromFile((Image**)&m_pPNGImage, m_AryEffectPNGImg.ElementAt(nIndex));
- BOOL bResult = IMGCommon::ImgThumbnail(m_AryEffectPNGImg.ElementAt(nIndex), SET_PIX(m_rcPNGImage.Width(), m_rcPNGImage.Height()), "D:\\003.png", 80, TRUE);
- INT nWidth = m_pPNGImage->GetWidth();
- INT nHeight = m_pPNGImage->GetHeight();
- if (nWidth == 0 || nHeight == 0)
- return FALSE;
- GetRgn(m_pPNGImage);
- m_pImagebak = m_pPNGImage->Clone(0, 0, m_pPNGImage->GetWidth(), m_pPNGImage->GetHeight(), PixelFormat32bppARGB);
- m_rcPNGImage = InitRect(m_pPNGImage);
- Rect destinationRect(m_rcPNGImage.left, m_rcPNGImage.top, m_rcPNGImage.Width(), m_rcPNGImage.Height());
- graph.DrawImage(m_pPNGImage, destinationRect, 0, 0, nWidth, nHeight, UnitPixel);
- InvalidateRect(m_rcBackground);
- return TRUE;
- }
- #endif
- BOOL CDlgRenderings::LoadPNGImageSuper(IN INT nIndex)
- {
- if (m_AryEffectPNGImg.GetSize() == 0 || (nIndex != 0 && (nIndex == m_nSelectPNGPosition)))
- return FALSE;
- m_nSelectPNGPosition = nIndex;
- // m_pbmp:最终显示PNG效果图的Bimap对象(PNG+客人相片 合二为一的结果);
- Graphics graph(m_pbmp);
- // 将对象区域全部不透明白色填充;
- graph.Clear(Color(255, 255, 255, 255));
- // 是否加载过;
- BOOL bLoaded = FALSE;
- CString strPNGFile = m_AryEffectPNGImg.ElementAt(nIndex);
- vector<STImageAlpha>::iterator it = m_vtPngAlphaInfo.begin();
- for (; it != m_vtPngAlphaInfo.end(); it++)
- {
- if (strPNGFile.CompareNoCase(it->PNGFileName) == 0)
- {
- bLoaded = TRUE;
- break;
- }
- }
- //#ifndef _DEBUG // Debug模式下删除出错;
- if (m_pPNGImage)
- delete m_pPNGImage;
- m_pPNGImage = NULL;
- if (m_pImagebak)
- delete m_pImagebak;
- m_pImagebak = NULL;
- //#endif
- IMGCommon::LoadImgFromFile((Image**)&m_pPNGImage, m_AryEffectPNGImg.ElementAt(nIndex));
- if (!bLoaded)
- {
- AutoThreadSection cs(&m_cs);
- STImageAlpha tagPngAlpha;
- tagPngAlpha.PNGFileName = strPNGFile;
- GetPNGAlphaRectInfo(m_pPNGImage, tagPngAlpha);
- m_vtPngAlphaInfo.push_back(tagPngAlpha);
- it = m_vtPngAlphaInfo.end() - 1;
- }
- INT nWidth = m_pPNGImage->GetWidth();
- INT nHeight = m_pPNGImage->GetHeight();
- if (nWidth == 0 || nHeight == 0)
- return FALSE;
- m_pImagebak = m_pPNGImage->Clone(0, 0, m_pPNGImage->GetWidth(), m_pPNGImage->GetHeight(), PixelFormat32bppARGB);
- Rect destinationRect(it->rcZoom.left, it->rcZoom.top, it->rcZoom.Width(), it->rcZoom.Height());
- graph.DrawImage(m_pPNGImage, destinationRect, 0, 0, nWidth, nHeight, UnitPixel);
- InvalidateRect(m_rcBackground);
- return TRUE;
- }
- CRect CDlgRenderings::InitRect(IN Image* pImage)
- {
- CRect rcImage(0, 0, 0, 0);
- if (pImage == NULL)
- return rcImage;
- CRect rcClient = m_rcWndClient;
- rcClient.right -= 220;
- rcImage = rcClient;
- INT nWidth = pImage->GetWidth();
- INT nHeight = pImage->GetHeight();
- float fscale = (float)nWidth / (float)nHeight;
- float rcscale = ((float)rcImage.Width()) / ((float)rcImage.Height());
- int rcwid = rcImage.Width();
- int rchei = rcImage.Height();
- int dt = 0;
- if (rcscale < fscale)
- {
- dt = (rchei - rcwid / fscale) / 2;
- rcImage.top += dt;
- rcImage.bottom -= dt;
- }
- else
- {
- dt = (rcwid - rchei*fscale) / 2;
- rcImage.left += dt;
- rcImage.right -= dt;
- }
- return rcImage;
- }
- #ifdef __UN_USE__
- BOOL CDlgRenderings::LoadJPGImage(IN INT nAlphaIndex, IN Image* pJpgImage, IN INT nXOffset, IN INT nYOffset)
- {
- // 判断透明区域索引是否有效;
- if (nAlphaIndex == -1 || m_rcarray[nAlphaIndex].GetSize() == 0)
- return FALSE;
- // JPG图像是否有效;
- if (pJpgImage == NULL || pJpgImage->GetWidth() == 0 || pJpgImage->GetHeight() == 0)
- return FALSE;
- // PNG底图是否有效;
- if (m_pPNGImage == NULL)
- return FALSE;
- Graphics graph(m_pbmp);
- CPoint pt1, pt2, pt3;
- int leng1, leng2, leng3;
- CPoint curpt;
- int leng;
- Graphics graph2(m_pPNGImage);
- int i;
- leng1 = leng2 = leng3 = 10000000;
- for (i = 0; i < m_rcarray[nAlphaIndex].GetSize(); i += 2)
- {
- curpt.x = m_rcarray[nAlphaIndex].ElementAt(i);
- curpt.y = m_rcarray[nAlphaIndex].ElementAt(i + 1);
- leng = GetLengFromPt(CPoint(0, 0), curpt); // 计算出斜边平方值,也就是两点间的距离;
- if (leng < leng1)
- {
- leng1 = leng;
- pt1 = curpt;
- }
- leng = GetLengFromPt(CPoint(m_pPNGImage->GetWidth(), 0), curpt);
- if (leng < leng2)
- {
- leng2 = leng;
- pt2 = curpt;
- }
- leng = GetLengFromPt(CPoint(0, m_pPNGImage->GetHeight()), curpt);
- if (leng < leng3)
- {
- leng3 = leng;
- pt3 = curpt;
- }
- }
- // m_tempscale为缩放值,点坐标要缩放;
- 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
- // 计算出每个透明区域的宽、高;
- int lengx = GetLengFromPt2(pt1, pt2);
- int lengy = GetLengFromPt2(pt1, pt3);
- CRect rc(0, 0, pJpgImage->GetWidth(), pJpgImage->GetHeight());
- RectFitDes(lengx, lengy, rc);
- #if 1
- float fx = (float)lengx / rc.Width();
- float fy = (float)lengy / rc.Height();
- if (nXOffset + lengx / fx >= pJpgImage->GetWidth())
- {// 是否要到右边缘;
- nXOffset = pJpgImage->GetWidth() - lengx / fx;
- }
- if (nYOffset + lengy / fy >= pJpgImage->GetHeight())
- {// 是否要到底边缘;
- nYOffset = pJpgImage->GetHeight() - lengy / fy;
- }
- #endif
- #if 0
- graph2.DrawImage(
- m_pJPGImage,
- destinationPoints,
- 3,
- nXOffset,
- nYOffset,
- rc.Width(),
- rc.Height(),
- UnitPixel,
- NULL,
- NULL,
- NULL);
- WriteTextLog("xoffset = %d, yoffset = %d", nXOffset, nYOffset);
- #else
- // 使用这种模式,可以放大缩小图片;
- RectF rf(pt1.x, pt1.y, lengx + 5, lengy + 5);
- graph2.DrawImage(pJpgImage, rf, nXOffset, nYOffset, rc.Width(), rc.Height(), UnitPixel);
- #endif
- graph2.DrawImage(m_pImagebak, 0, 0);
- Rect destinationRect(m_rcPNGImage.left, m_rcPNGImage.top, m_rcPNGImage.Width(), m_rcPNGImage.Height());
- graph.DrawImage(m_pPNGImage, destinationRect, 0, 0, m_pPNGImage->GetWidth(), m_pPNGImage->GetHeight(), UnitPixel);
- #if 0
- // 刷新范围太大了,用户体验不好!;
- InvalidateRect(m_rcBackground);
- #else
- // 局部区域刷新;
- float fs = (float)m_rcPNGImage.Width() / m_pPNGImage->GetWidth();
- pt1.x *= fs;
- pt1.y *= fs;
- pt2.x *= fs;
- pt2.y *= fs;
- pt3.x *= fs;
- pt3.y *= fs;
- float fs2 = (float)1;
- pt1.Offset(m_rcPNGImage.left, m_rcPNGImage.top);
- pt2.Offset(m_rcPNGImage.left, m_rcPNGImage.top);
- pt3.Offset(m_rcPNGImage.left, m_rcPNGImage.top);
- pt1.Offset(m_rcBackground.left, m_rcBackground.top);
- pt2.Offset(m_rcBackground.left, m_rcBackground.top);
- pt3.Offset(m_rcBackground.left, m_rcBackground.top);
- InvalidateRect(CRect(pt1.x - 6, pt1.y - 6, pt2.x + 8, pt3.y + 8));
- #endif
- return TRUE;
- }
- #endif
- BOOL CDlgRenderings::LoadJPGImageSuper(STOffSetInfo *pOffSetInfo)
- {
- // 判断透明区域索引是否有效;
- if (pOffSetInfo->nIndexOfAlpha == -1)
- return FALSE;
- // JPG图像是否有效;
- if (pOffSetInfo->pImage == NULL || pOffSetInfo->pImage->GetWidth() == 0 || pOffSetInfo->pImage->GetHeight() == 0)
- return FALSE;
- // PNG底图是否有效;
- if (m_pPNGImage == NULL)
- return FALSE;
- // 获取出透明区域的三点;
- CPoint ptOrigin, ptOriginX, ptOriginY;
- CString strPNGFile = m_AryEffectPNGImg.ElementAt(m_nSelectPNGPosition);
- STAlphaPt *pAlphaPt = NULL;
- vector<STImageAlpha>::iterator it;
- for (it = m_vtPngAlphaInfo.begin(); it != m_vtPngAlphaInfo.end(); it++)
- {
- if (strPNGFile.CompareNoCase(it->PNGFileName) == 0)
- {
- for (vector<STAlphaPt>::iterator iit = it->vtAlphaPt.begin(); iit != it->vtAlphaPt.end(); iit++)
- {
- if (pOffSetInfo->nIndexOfAlpha == iit->nAlphaIndex)
- {
- pAlphaPt = (STAlphaPt*)(&*iit);
- ptOrigin = iit->ptOrigin;
- ptOriginX = iit->ptOriginX;
- ptOriginY = iit->ptOriginY;
- break;
- }
- }
- break;
- }
- }
- if (pAlphaPt == NULL)
- return FALSE;
- // 将坐标系从800*800缩放回png原图坐标系;
- ptOrigin.x *= it->fScale;
- ptOrigin.y *= it->fScale;
- ptOriginX.x *= it->fScale;
- ptOriginX.y *= it->fScale;
- ptOriginY.x *= it->fScale;
- ptOriginY.y *= it->fScale;
- // 获取透明区域的长宽;
- INT nWidth = GetLengFromPt2(ptOrigin, ptOriginX);
- INT nHeight = GetLengFromPt2(ptOrigin, ptOriginY);
- CRect rcZoom(0, 0, pOffSetInfo->pImage->GetWidth(), pOffSetInfo->pImage->GetHeight());
- RectFitDes(nWidth, nHeight, rcZoom);
- // 判断移动的点是否到达边缘;
- float fsx = (float)nWidth / rcZoom.Width();
- float fsy = (float)nHeight / rcZoom.Height();
- //if (nXOffset + nWidth / fsx >= pJpgImage->GetWidth())
- {//若到边缘,重新指定;
- pOffSetInfo->nXOffSet = (pOffSetInfo->pImage->GetWidth() - nWidth / fsx)/2;
- }
- //if (nYOffset + nHeight / fsy >= pJpgImage->GetHeight())
- {//若到边缘,重新指定;
- //pOffSetInfo->nYOffSet = (pOffSetInfo->pImage->GetHeight() - nHeight / fsy)/3;
- }
- Graphics graph(m_pbmp);
- Graphics gra_png(m_pPNGImage);
- // 将JPG画到PNG原图上指定透明区域;
- RectF rfAlpha(ptOrigin.x - 5, ptOrigin.y - 5, nWidth + 10, nHeight + 10);
- gra_png.DrawImage(pOffSetInfo->pImage, rfAlpha, pOffSetInfo->nXOffSet, pOffSetInfo->nYOffSet, rcZoom.Width(), rcZoom.Height(), UnitPixel);
- gra_png.DrawImage(m_pImagebak, 0, 0);
- // 再将png画到背景图上;
- Rect rcPng(it->rcZoom.left, it->rcZoom.top, it->rcZoom.Width(), it->rcZoom.Height());
- graph.DrawImage(m_pPNGImage, rcPng, 0, 0, m_pPNGImage->GetWidth(), m_pPNGImage->GetHeight(), UnitPixel);
- // 刷新透明区域;
- ptOrigin = AlphaPt2WndPt(pAlphaPt->ptOrigin, it->rcZoom, it->fScale);
- ptOriginX = AlphaPt2WndPt(pAlphaPt->ptOriginX, it->rcZoom, it->fScale);
- ptOriginY = AlphaPt2WndPt(pAlphaPt->ptOriginY, it->rcZoom, it->fScale);
- InvalidateRect(CRect(ptOrigin.x - 6, ptOrigin.y - 6, ptOriginX.x + 8, ptOriginY.y + 8));
- return TRUE;
- }
- BOOL CDlgRenderings::LoadJPGImageSuperEx(IN INT nAlphaIndex, IN Image * pJpgImage, IN float& fs, IN INT nXOffset, IN INT nYOffset)
- {
- // 判断透明区域索引是否有效;
- if (nAlphaIndex == -1)
- return FALSE;
- // JPG图像是否有效;
- if (pJpgImage == NULL || pJpgImage->GetWidth() == 0 || pJpgImage->GetHeight() == 0)
- return FALSE;
- // PNG底图是否有效;
- if (m_pPNGImage == NULL)
- return FALSE;
- // 获取出透明区域的三点;
- CPoint ptOrigin, ptOriginX, ptOriginY;
- CString strPNGFile = m_AryEffectPNGImg.ElementAt(m_nSelectPNGPosition);
- STAlphaPt *pAlphaPt = NULL;
- vector<STImageAlpha>::iterator it;
- for (it = m_vtPngAlphaInfo.begin(); it != m_vtPngAlphaInfo.end(); it++)
- {
- if (strPNGFile.CompareNoCase(it->PNGFileName) == 0)
- {
- for (vector<STAlphaPt>::iterator iit = it->vtAlphaPt.begin(); iit != it->vtAlphaPt.end(); iit++)
- {
- if (nAlphaIndex == iit->nAlphaIndex)
- {
- pAlphaPt = (STAlphaPt*)(&*iit);
- ptOrigin = iit->ptOrigin;
- ptOriginX = iit->ptOriginX;
- ptOriginY = iit->ptOriginY;
- break;
- }
- }
- break;
- }
- }
- if (pAlphaPt == NULL)
- return FALSE;
- // 将坐标系从800*800缩放回png原图坐标系;
- ptOrigin.x *= it->fScale;
- ptOrigin.y *= it->fScale;
- ptOriginX.x *= it->fScale;
- ptOriginX.y *= it->fScale;
- ptOriginY.x *= it->fScale;
- ptOriginY.y *= it->fScale;
- // 获取透明区域的长宽;
- INT nWidth = GetLengFromPt2(ptOrigin, ptOriginX);
- INT nHeight = GetLengFromPt2(ptOrigin, ptOriginY);
- CRect rcZoom(0, 0, pJpgImage->GetWidth(), pJpgImage->GetHeight());
- RectFitDes(nWidth, nHeight, rcZoom);
- // 判断移动的点是否到达边缘;
- float fsx = (float)nWidth / rcZoom.Width();
- float fsy = (float)nHeight / rcZoom.Height();
- if (nXOffset + nWidth / fsx *fs >= pJpgImage->GetWidth())
- {//若到边缘,重新指定;
- nXOffset = pJpgImage->GetWidth() - nWidth / fsx *fs;
- if (nXOffset < 0)
- {
- nXOffset = 0;
- fs = 1.0;
- }
- }
- if (nYOffset + nHeight / fsy *fs >= pJpgImage->GetHeight())
- {//若到边缘,重新指定;
- nYOffset = pJpgImage->GetHeight() - nHeight / fsy *fs;
- if (nYOffset < 0)
- {
- nYOffset = 0;
- fs = 1.0;
- }
- }
- Graphics graph(m_pbmp);
- Graphics gra_png(m_pPNGImage);
- // 将JPG画到PNG原图上指定透明区域;
- RectF rfAlpha(ptOrigin.x - 5, ptOrigin.y - 5, nWidth + 10, nHeight + 10);
- gra_png.DrawImage(pJpgImage, rfAlpha, nXOffset, nYOffset, rcZoom.Width()*fs, rcZoom.Height()*fs, UnitPixel);
- gra_png.DrawImage(m_pImagebak, 0, 0);
- // 再将png画到背景图上;
- Rect rcPng(it->rcZoom.left, it->rcZoom.top, it->rcZoom.Width(), it->rcZoom.Height());
- graph.DrawImage(m_pPNGImage, rcPng, 0, 0, m_pPNGImage->GetWidth(), m_pPNGImage->GetHeight(), UnitPixel);
- // 刷新透明区域;
- ptOrigin = AlphaPt2WndPt(pAlphaPt->ptOrigin, it->rcZoom, it->fScale);
- ptOriginX = AlphaPt2WndPt(pAlphaPt->ptOriginX, it->rcZoom, it->fScale);
- ptOriginY = AlphaPt2WndPt(pAlphaPt->ptOriginY, it->rcZoom, it->fScale);
- InvalidateRect(CRect(ptOrigin.x - 6, ptOrigin.y - 6, ptOriginX.x + 8, ptOriginY.y + 8));
- return TRUE;
- }
- INT CDlgRenderings::IsPointInAlphaRect(IN CPoint point)
- {
- INT nAlphaIndex = -1;
- if (m_nSelectPNGPosition == -1)
- return -1;
- CString strPNGfile = m_AryEffectPNGImg.ElementAt(m_nSelectPNGPosition);
- for (vector<STImageAlpha>::iterator it = m_vtPngAlphaInfo.begin(); it != m_vtPngAlphaInfo.end(); it++)
- {
- if (strPNGfile.CompareNoCase(it->PNGFileName) == 0)
- {
- // 将窗口坐标系转成透明区域坐标系;
- point = WndPt2AlphaPt(point, it->rcZoom, it->fScale);
- for (vector<STAlphaPt>::iterator iit = it->vtAlphaPt.begin(); iit != it->vtAlphaPt.end(); iit++)
- {
- CRect rcAlpha(iit->ptOrigin.x, iit->ptOrigin.y, iit->ptOriginX.x, iit->ptOriginY.y);
- if (rcAlpha.PtInRect(point))
- {
- nAlphaIndex = iit->nAlphaIndex;
- break;
- }
- }
- break;
- }
- }
- return nAlphaIndex;
- }
- BOOL CDlgRenderings::PreTranslateMessage(MSG* pMsg)
- {
- if (pMsg->message == WM_KEYDOWN)
- {
- // 获取按下时的点;
- CPoint pt;
- GetCursorPos(&pt);
- m_nCurAlphaIndex = IsPointInAlphaRect(pt);
- if (m_vtOffSetInfo.size() == 0)
- return FALSE;
- // 找到透明区域;
- vector<STOffSetInfo>::iterator it = m_vtOffSetInfo.begin();
- for (; it != m_vtOffSetInfo.end(); it++)
- {
- if (it->nIndexOfAlpha == m_nCurAlphaIndex)
- break;
- }
- // 未找到退出;
- if (it == m_vtOffSetInfo.end() || it->nIndexOfAlpha == -1)
- return FALSE;
- switch (pMsg->wParam)
- {
- case VK_RIGHT:
- it->nXOffSet -= 120;
- it->nXOffSet = it->nXOffSet < 0 ? 0 : it->nXOffSet;
- LoadJPGImageSuperEx(m_nCurAlphaIndex, it->pImage, it->fScale, it->nXOffSet, it->nYOffSet);
- break;
- case VK_LEFT:
- it->nXOffSet += 120;
- LoadJPGImageSuperEx(m_nCurAlphaIndex, it->pImage, it->fScale, it->nXOffSet, it->nYOffSet);
- break;
- case VK_UP:
- it->nYOffSet += 120;
- LoadJPGImageSuperEx(m_nCurAlphaIndex, it->pImage, it->fScale, it->nXOffSet, it->nYOffSet);
- break;
- case VK_DOWN:
- it->nYOffSet -= 120;
- it->nYOffSet = it->nYOffSet < 0 ? 0 : it->nYOffSet;
- LoadJPGImageSuperEx(m_nCurAlphaIndex, it->pImage, it->fScale, it->nXOffSet, it->nYOffSet);
- break;
- }
- // 从这里返回TRUE,则其他控件就不会响应按下事件;
- return TRUE;
- }
- return CDialog::PreTranslateMessage(pMsg);
- }
- /************************************************************************/
- /* 函数:[4/12/2017 Jeff];
- /* 描述:;
- /* 参数:;
- /* [IN] :;
- /* [OUT] :;
- /* [IN/OUT] :;
- /* 返回:void;
- /* 注意:;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- CPoint CDlgRenderings::WndPt2AlphaPt(IN const CPoint& WndPt)
- {
- CPoint AlphaPt = WndPt;
- // 1.首先,将窗口坐标系偏移到背景图坐标系(偏移原点坐标,背景图坐标系是m_rcBackground);
- AlphaPt.Offset(-m_rcBackground.left, -m_rcBackground.top);
- // 2.再次从背景图坐标系偏移到PNG显示层坐标系(偏移原点坐标,PNG显示层是m_rcPNGImage);
- AlphaPt.Offset(-m_rcPNGImage.left, -m_rcPNGImage.top);
- // 计算出png原图缩放显示到窗口的缩放比例;
- float fScale = (float)m_rcPNGImage.Width() / m_pPNGImage->GetWidth();
- // 3.再将窗口点缩放到PNG原图比例;
- AlphaPt.x /= fScale;
- AlphaPt.y /= fScale;
- // 计算出png原图缩放到(800x800)的显示区域的比例值;
- // 注:800x800的区域,是计算透明区域的缩放区域;
- // 4.将点缩放到800x800的区域;
- AlphaPt.x /= m_tempscale;
- AlphaPt.y /= m_tempscale;
- return AlphaPt;
- }
- CPoint CDlgRenderings::WndPt2AlphaPt(IN const CPoint & WndPt, IN CRect& rcPNGImage, IN float fScale)
- {
- CPoint AlphaPt = WndPt;
- // 1.首先,将窗口坐标系偏移到背景图坐标系(偏移原点坐标,背景图坐标系是m_rcBackground);
- AlphaPt.Offset(-m_rcBackground.left, -m_rcBackground.top);
- // 2.再次从背景图坐标系偏移到PNG显示层坐标系(偏移原点坐标,PNG显示层是m_rcPNGImage);
- AlphaPt.Offset(-rcPNGImage.left, -rcPNGImage.top);
- // 计算出png原图缩放显示到窗口的缩放比例;
- float fs = (float)rcPNGImage.Width() / m_pPNGImage->GetWidth();
- // 3.再将窗口点缩放到PNG原图比例;
- AlphaPt.x /= fs;
- AlphaPt.y /= fs;
- // 计算出png原图缩放到(800x800)的显示区域的比例值;
- // 注:800x800的区域,是计算透明区域的缩放区域;
- // 4.将点缩放到800x800的区域;
- AlphaPt.x /= fScale;
- AlphaPt.y /= fScale;
- return AlphaPt;
- }
- /************************************************************************/
- /* 函数:[4/12/2017 Jeff];
- /* 描述:;
- /* 参数:;
- /* [IN] :;
- /* [OUT] :;
- /* [IN/OUT] :;
- /* 返回:void;
- /* 注意:;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- CPoint CDlgRenderings::AlphaPt2WndPt(IN const CPoint& AlphaPt)
- {
- CPoint WndPt = AlphaPt;
- // 计算出png原图缩放到(800x800)的显示区域的比例值;
- // 注:800x800的区域,是计算透明区域的缩放区域;
- // 1.缩放到png原图比例;
- WndPt.x *= m_tempscale;
- WndPt.y *= m_tempscale;
- // 计算出png原图缩放显示到窗口的缩放比例;
- float fScale = (float)m_rcPNGImage.Width() / m_pPNGImage->GetWidth();
- // 2.再将窗口点缩放到PNG显示层比例;
- WndPt.x *= fScale;
- WndPt.y *= fScale;
- // 3.PNG显示层坐标系偏移到背景图坐标系(偏移原点坐标,PNG显示层是m_rcPNGImage);
- WndPt.Offset(m_rcPNGImage.left, m_rcPNGImage.top);
- // 4.背景图坐标系偏移到窗口坐标系(偏移原点坐标,背景图坐标系是m_rcBackground);
- WndPt.Offset(m_rcBackground.left, m_rcBackground.top);
- return WndPt;
- }
- CPoint CDlgRenderings::AlphaPt2WndPt(IN const CPoint & AlphaPt, IN CRect & rcPNGImage, IN float fScale)
- {
- CPoint WndPt = AlphaPt;
- // 计算出png原图缩放到(800x800)的显示区域的比例值;
- // 注:800x800的区域,是计算透明区域的缩放区域;
- // 1.缩放到png原图比例;
- WndPt.x *= fScale;
- WndPt.y *= fScale;
- // 计算出png原图缩放显示到窗口的缩放比例;
- float fs = (float)rcPNGImage.Width() / m_pPNGImage->GetWidth();
- // 2.再将窗口点缩放到PNG显示层比例;
- WndPt.x *= fs;
- WndPt.y *= fs;
- // 3.PNG显示层坐标系偏移到背景图坐标系(偏移原点坐标,PNG显示层是m_rcPNGImage);
- WndPt.Offset(rcPNGImage.left, rcPNGImage.top);
- // 4.背景图坐标系偏移到窗口坐标系(偏移原点坐标,背景图坐标系是m_rcBackground);
- WndPt.Offset(m_rcBackground.left, m_rcBackground.top);
- return WndPt;
- }
- BOOL CDlgRenderings::IsAlphaIndexExist(IN INT nIndex, vector<STAlphaPt>& vtAlpha)
- {
- BOOL bExist = FALSE;
- for (vector<STAlphaPt>::iterator it = vtAlpha.begin(); it != vtAlpha.end(); it++)
- {
- if (nIndex == it->nAlphaIndex)
- {
- bExist = TRUE;
- break;
- }
- }
- return bExist;
- }
- BOOL CDlgRenderings::IsPngAlphaExist(IN CString strPng, vector<STImageAlpha>& vtPngAlpha)
- {
- BOOL bExist = FALSE;
- for (vector<STImageAlpha>::iterator it = vtPngAlpha.begin(); it != vtPngAlpha.end(); it++)
- {
- if (strPng.CompareNoCase(it->PNGFileName) == 0)
- {
- bExist = TRUE;
- break;
- }
- }
- return bExist;
- }
- /************************************************************************/
- /* 函数:[4/12/2017 Jeff];
- /* 描述:;
- /* 参数:;
- /* [IN] :;
- /* [OUT] :;
- /* [IN/OUT] :;
- /* 返回:void;
- /* 注意:;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- void CDlgRenderings::GetPNGAlphaRectInfo(IN Bitmap * pOriginImage, IN OUT STImageAlpha & pngAlpha)
- {
- if (pOriginImage == NULL || pOriginImage->GetWidth() <= 0 || pOriginImage->GetHeight() <= 0)
- return;
- BOOL bUseOrigin = FALSE;
- Bitmap *pZoomObj = NULL;
- pngAlpha.rcZoom = InitRect(pOriginImage);
- if (pOriginImage->GetWidth() > 800 || pOriginImage->GetHeight() > 800)
- {
- // 使用800长宽的矩形来缩放png原图,并且基于该尺寸来获取透明区域;
- CRect rcZoom(0, 0, 800, 800);
- // 计算出适合png原图的rcZoom显示位置;
- RectFitDes(pOriginImage->GetWidth(), pOriginImage->GetHeight(), rcZoom);
- // 创建缩放对象;
- pZoomObj = new Bitmap(rcZoom.Width(), rcZoom.Height(), PixelFormat32bppPARGB);
- if (pZoomObj == NULL)
- return;
- // 将原图画在Zoom对象图中;
- Graphics graphics(pZoomObj);
- graphics.Clear(Color(0, 0, 0, 0));
- graphics.DrawImage(pOriginImage, 0, 0, pZoomObj->GetWidth(), pZoomObj->GetHeight());
- pngAlpha.fScale = (float)pOriginImage->GetWidth() / pZoomObj->GetWidth();
- }
- else
- {
- // 使用原图;
- pZoomObj = pOriginImage->Clone(0, 0, pOriginImage->GetWidth(), pOriginImage->GetHeight(), PixelFormat32bppPARGB);
- bUseOrigin = TRUE;
- pngAlpha.fScale = 1.0;
- }
- UINT *pixels = NULL;
- BitmapData bitmapdata;
- Rect rcZoom(0, 0, pZoomObj->GetWidth(), pZoomObj->GetHeight());
- // 获取缩放图的位图信息;
- pZoomObj->LockBits(&rcZoom, ImageLockModeRead, PixelFormat32bppPARGB, &bitmapdata);
- pixels = (UINT *)bitmapdata.Scan0;
- DWORD dwWidth = bitmapdata.Stride / 4;
- // 像素(x,y)的颜色;
- Color color;
- // 像素(x,y)四周8个方向的像素颜色:
- // (x-1,y-1);
- // (x-0,y-1);
- // (x+1,y-1);
- // (x-1,y-0);
- // (x+1,y-0);
- // (x-1,y+1);
- // (x-0,y+1);
- // (x+1,y+1);
- Color color1, color2, color3, color4, color5, color6, color7, color8;
- // m_rcarray数组,用于记录PNG图片里的alpha色小于200的像素点坐标;
- CArray<int, int> AryAlphaRect[RCARRARCOUNT];
- for (int nAlphaIndex = 0; nAlphaIndex < RCARRARCOUNT; nAlphaIndex++)
- AryAlphaRect[nAlphaIndex].RemoveAll(); // 清空以前的;
- for (INT row = 0; row < rcZoom.Height; ++row)
- {
- for (INT col = 0; col < rcZoom.Width - 1; ++col)
- {
- // 将PNG图片当前像素(col,row)点的颜色值填充到color对象;
- color.SetValue(pixels[row * dwWidth + col]);
- // Color::GetA() 方法获取此Color对象的alpha分量(返回这个颜色的alpha分量)。
- BYTE byalpha = color.GetA();
- if (byalpha < 200)
- {
- CArray<int, int>*pArray = NULL;
- for (int nAlphaIndex = 0; nAlphaIndex < RCARRARCOUNT; nAlphaIndex++)
- {
- if (AryAlphaRect[nAlphaIndex].GetSize() && pArray == NULL)
- {
- // 从区域nAlphaIndex的第一个点开始,判断当前像素点(col,row)是否属于该区域的连续同色;
- double x = AryAlphaRect[nAlphaIndex].ElementAt(0);
- double y = AryAlphaRect[nAlphaIndex].ElementAt(1);
- // x0,y0作为原点;
- int x0 = (int)x;
- int y0 = (int)y;
- // col、row为当前点;
- // x、y为对照点;
- double dtx = col - x;
- double dty = row - y;
- // 求得tan或cot值;
- if (abs(dtx) > abs(dty))
- {// 左右象限(3、4、7、8);
- if (dty)
- {// 在原点下方(4、7);
- dtx /= abs(dty); // cot;
- dty /= abs(dty); // 1;
- }
- else
- {// 在原点上方(3、8);
- if (dtx > 0)
- {//在原点右方(3);
- dtx = 1;
- }
- else if (dtx < 0)
- {//在原点左方(8);
- dtx = -1;
- }
- }
- }
- else
- {// 上下象限(1、2、5、6);
- if (dtx)
- {//在原点右方(2、5);
- dty /= abs(dtx); // tan;
- dtx /= abs(dtx); // 1;
- }
- else
- {//在原点左方(1、6);
- if (dty > 0)
- {//在原点下方(6);
- dty = 1;
- }
- else if (dtx < 0)
- {//在原点上方(1);
- dty = -1;
- }
- }
- }
- // 此时dtx或dty已为tan或cot值,当tan或cot的值大于3时,角度是72或18度左右;
- 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 = FALSE;
- while (1)
- {
- x += dtx;
- y += dty;
- if (x >= (rcZoom.Width - 1) || x < 1)break;
- if (y >= (rcZoom.Height - 1) || y < 1)break;
- if (col > x0)
- {//在原点右侧;
- if (x < x0 || x > col)
- {// 新点不在原点和像素点x坐标之间;
- break;
- }
- }
- if (col < x0)
- {//在原点左侧;
- if (x > x0 || x < col)
- {// 新点不在原点和像素点x坐标之间;
- break;
- }
- }
- if (row > y0)
- {//在原点下方;
- if (y < y0 || y > row)
- {// 新点不在原点和像素点y坐标之间;
- break;
- }
- }
- if (row < y0)
- {//在原点上方;
- if (y > y0 || y < row)
- {// 新点不在原点和像素点y坐标之间;
- break;
- }
- }
- color.SetValue(pixels[(int)y * dwWidth + (int)x]);
- if (color.GetA() == 255)
- {
- color1.SetValue(pixels[(int)(y - 1) * dwWidth + (int)(x - 1)]);
- color2.SetValue(pixels[(int)(y - 1) * dwWidth + (int)(x - 0)]);
- color3.SetValue(pixels[(int)(y - 1) * dwWidth + (int)(x + 1)]);
- color4.SetValue(pixels[(int)(y - 0) * dwWidth + (int)(x - 1)]);
- color5.SetValue(pixels[(int)(y - 0) * dwWidth + (int)(x + 1)]);
- color6.SetValue(pixels[(int)(y + 1) * dwWidth + (int)(x - 1)]);
- color7.SetValue(pixels[(int)(y + 1) * dwWidth + (int)(x - 0)]);
- color8.SetValue(pixels[(int)(y + 1) * dwWidth + (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)
- {// 当前像素4周8个方向的像素点颜色与当前像素一致,表明为连续区域;
- bFind = 1;
- break;
- }
- }
- }
- if (!bFind)
- {// 不是连续点,则开一个数组保存这块新的区域;
- pArray = &(AryAlphaRect[nAlphaIndex]);
- }
- }
- }
- if (pArray == NULL)
- {// 未找到相邻同色的点;
- BOOL bcontinue = 1;
- for (int yy = 0; yy < RCARRARCOUNT; yy++)
- {
- if (AryAlphaRect[yy].GetSize() == 0)
- {
- pArray = &(AryAlphaRect[yy]);
- bcontinue = 0;
- break;
- }
- }
- if (bcontinue)
- continue;
- }
- pArray->Add(col); // x坐标;
- pArray->Add(row); // y坐标;
- }
- }
- }
- pZoomObj->UnlockBits(&bitmapdata);
- if (pZoomObj )
- delete pZoomObj;
- pZoomObj = NULL;
- for (int i = 0; i < RCARRARCOUNT; i++)
- {
- // 计算出透明区域的3个有效点;
- CPoint ptCur, ptOrigin, ptOriginX, ptOriginY;
- int dwLeng = 100000000, dwLengO = 100000000, dwLengX = 100000000, dwLengY = 100000000;
- if (AryAlphaRect[i].GetSize() > 0)
- {
- for (int j = 0; j < AryAlphaRect[i].GetSize(); j += 2)
- {
- ptCur.x = AryAlphaRect[i].ElementAt(j);
- ptCur.y = AryAlphaRect[i].ElementAt(j + 1);
- // 原点;
- dwLeng = GetLengFromPt(CPoint(0, 0), ptCur);
- if (dwLeng < dwLengO)
- {
- dwLengO = dwLeng;
- ptOrigin = ptCur;
- }
- // 右边点;
- dwLeng = GetLengFromPt(CPoint(pOriginImage->GetWidth(), 0), ptCur);
- if (dwLeng < dwLengX)
- {
- dwLengX = dwLeng;
- ptOriginX = ptCur;
- }
- // 下边点;
- dwLeng = GetLengFromPt(CPoint(0, pOriginImage->GetHeight()), ptCur);
- if (dwLeng < dwLengY)
- {
- dwLengY = dwLeng;
- ptOriginY = ptCur;
- }
- }
- if (!IsAlphaIndexExist(i, pngAlpha.vtAlphaPt))
- { // 保存透明信息;
- STAlphaPt ptAlpha;
- ptAlpha.nAlphaIndex = i;
- ptAlpha.ptOrigin = ptOrigin;
- ptAlpha.ptOriginX = ptOriginX;
- ptAlpha.ptOriginY = ptOriginY;
- pngAlpha.vtAlphaPt.push_back(ptAlpha);
- }
- }
- }
- }
- /************************************************************************/
- /* 函数:[4/12/2017 Jeff];
- /* 描述:;
- /* 参数:;
- /* [IN] :;
- /* [OUT] :;
- /* [IN/OUT] :;
- /* 返回:void;
- /* 注意:;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- DWORD CDlgRenderings::Thread_GetAllPNGInfo(IN LPVOID lpVoid)
- {
- if (lyfzGlobal::g_strPathOfPNG.IsEmpty() || !PathFileExists(lyfzGlobal::g_strPathOfPNG))
- return 0;
- filehelpImpl ffhelp;
- STR_VEC vtfiles;
- ffhelp.getfiles_findout_subfolder(lyfzGlobal::g_strPathOfPNG, _T("*.png"), &vtfiles);
- if (vtfiles.size() == 0)
- return 0;
- Image *pImage = NULL;
- STR_VEC::iterator it = vtfiles.begin();
- for (; it != vtfiles.end(); it++)
- {
- // 加载png原图;
- IMGCommon::LoadImgFromFile(&pImage, it->c_str());
- if (pImage)
- {
- // 获取png透明区域详情;
- if (!IsPngAlphaExist(it->c_str(), m_vtPngAlphaInfo))
- {
- STImageAlpha pngAlpha;
- pngAlpha.PNGFileName = it->c_str();
- GetPNGAlphaRectInfo((Bitmap*)pImage, pngAlpha);
- m_vtPngAlphaInfo.push_back(pngAlpha);
- }
- delete pImage;
- pImage = NULL;
- }
- }
- return 0;
- }
- void CDlgRenderings::DrawAlphaEdge(IN CPoint pt, IN BOOL bWhite)
- {
- if (m_nSelectPNGPosition == -1)
- return;
- m_ptLastRectangle = pt;
- // 获取png信息;
- STAlphaPt *pAlphaPt = NULL;
- STImageAlpha *pImageAlpha = NULL;
- CString strPNGFile = m_AryEffectPNGImg.ElementAt(m_nSelectPNGPosition);
- for (vector<STImageAlpha>::iterator it = m_vtPngAlphaInfo.begin(); it != m_vtPngAlphaInfo.end(); it++ )
- {
- if (strPNGFile.CompareNoCase(it->PNGFileName) == 0)
- {
- pImageAlpha = (STImageAlpha *)(&*it);
- // 将窗口坐标系转成透明区域坐标系;
- pt = WndPt2AlphaPt(pt, it->rcZoom, it->fScale);
- for (vector<STAlphaPt>::iterator iit = it->vtAlphaPt.begin(); iit != it->vtAlphaPt.end(); iit++)
- {
- CRect rcAlpha(iit->ptOrigin.x, iit->ptOrigin.y, iit->ptOriginX.x, iit->ptOriginY.y);
- if (rcAlpha.PtInRect(pt))
- {
- pAlphaPt = (STAlphaPt*)(&*iit);
- break;
- }
- }
- break;
- }
- }
- if (pImageAlpha == NULL || pAlphaPt == NULL )
- return;
- // 获取出透明区域的三点;
- CPoint ptOrigin = pAlphaPt->ptOrigin, ptOriginX = pAlphaPt->ptOriginX, ptOriginY = pAlphaPt->ptOriginY;
- // 将坐标系从800*800缩放回png原图坐标系;
- ptOrigin.x *= pImageAlpha->fScale;
- ptOrigin.y *= pImageAlpha->fScale;
- ptOriginX.x *= pImageAlpha->fScale;
- ptOriginX.y *= pImageAlpha->fScale;
- ptOriginY.x *= pImageAlpha->fScale;
- ptOriginY.y *= pImageAlpha->fScale;
- // 画边框;
- Graphics graphics(m_pbmp);
- Graphics graphics1(m_pPNGImage);
- // 画到PNG原图上指定透明区域;
- Rect rfAlpha(ptOrigin.x + 10, ptOrigin.y + 10, ptOriginX.x - ptOrigin.x - 20, ptOriginY.y - ptOrigin.y - 20);
- // 创建画笔;
- if (!bWhite)
- {
- Pen blackPen(Color(255, 255, 0, 0), 1);
- // 画矩形到png上;
- graphics1.DrawRectangle(&blackPen, rfAlpha);
- }
- else
- {
- STOffSetInfo *pOffSet = NULL;
- for (vector<STOffSetInfo>::iterator it = m_vtOffSetInfo.begin(); it != m_vtOffSetInfo.end(); it++ )
- {
- if (pAlphaPt->nAlphaIndex == it->nIndexOfAlpha)
- {
- pOffSet = (STOffSetInfo *)(&*it);
- break;
- }
- }
- if (pOffSet != NULL && pOffSet->pImage)
- {
- LoadJPGImageSuperEx(pOffSet->nIndexOfAlpha, pOffSet->pImage, pOffSet->fScale, pOffSet->nXOffSet, pOffSet->nYOffSet);
- return;
- }
- Pen blackPen(Color(255, 255, 255, 255), 3);
- // 画矩形到png上;
- graphics1.DrawRectangle(&blackPen, rfAlpha);
- }
- // 再将png画到背景图上;
- Rect rcPng(pImageAlpha->rcZoom.left, pImageAlpha->rcZoom.top, pImageAlpha->rcZoom.Width(), pImageAlpha->rcZoom.Height());
- graphics.DrawImage(m_pPNGImage, rcPng, 0, 0, m_pPNGImage->GetWidth(), m_pPNGImage->GetHeight(), UnitPixel);
- // 刷新透明区域;
- ptOrigin = AlphaPt2WndPt(pAlphaPt->ptOrigin, pImageAlpha->rcZoom, pImageAlpha->fScale);
- ptOriginX = AlphaPt2WndPt(pAlphaPt->ptOriginX, pImageAlpha->rcZoom, pImageAlpha->fScale);
- ptOriginY = AlphaPt2WndPt(pAlphaPt->ptOriginY, pImageAlpha->rcZoom, pImageAlpha->fScale);
- InvalidateRect(CRect(ptOrigin.x - 6, ptOrigin.y - 6, ptOriginX.x + 8, ptOriginY.y + 8));
- }
- void CDlgRenderings::AddNewImageItem(IN CString strImageFile)
- {
- // 文件路径是否有效;
- if (!PathFileExists(strImageFile))
- return;
- // 加载图片;
- BOOL bZoom = FALSE;
- Bitmap *pImage = NULL;
- IMGCommon::LoadImgFromFile((Image**)&pImage, strImageFile);
- if ( pImage && pImage->GetWidth() != 0 )
- {
- if ( pImage->GetWidth() > 2000 || pImage->GetHeight() > 2000 )
- {// 尺寸大于2000的,缩放;
- bZoom = TRUE;
- CRect rcZoom(0, 0, 2000, 2000);
- RectFitDes(pImage->GetWidth(), pImage->GetHeight(), rcZoom);
- // 新建缩略对象,并替换原来的;
- Bitmap *pZoomImage = new Bitmap(rcZoom.Width(), rcZoom.Height(), PixelFormat32bppARGB);
- // 将原图画在缩略图对象上;
- Graphics graphics(pZoomImage);
- graphics.Clear(Color(0,0,0,0)); // 透明黑填充;
- graphics.DrawImage(pImage, 0, 0, pZoomImage->GetWidth(), pZoomImage->GetHeight());
- pImage = pZoomImage;
- }
- // 将效果图保存到指定目录;
- CString strImageName = _T("");
- CString strImageDestPath = _T("");
- // 获取文件名;
- INT nIndex = strImageFile.ReverseFind(_T('\\'));
- strImageName = strImageFile.Mid(nIndex+1);
- strImageName = strImageName.Left(strImageName.Find(_T('.')));
- // 保存文件;
- strImageDestPath.Format(_T("%s\\%s.png"), g_strPathOfPNG, strImageName);
- IMGCommon::SaveImg2newfile(pImage, strImageDestPath, 100);
- // 添加到主程序中;
- m_AryEffectPNGImg.Add(strImageDestPath);
- // 创建缩放区域,并适用图片比例;
- CRect rcZoom(0, 0, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT);
- RectFitDes(pImage->GetWidth(), pImage->GetHeight(), rcZoom);
- // 创建背景图;
- Bitmap *pZoomImage = new Bitmap(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, PixelFormat32bppARGB);
- Graphics grahpics(pZoomImage);
- // 产生边框效果,先用灰色填充,再用白色画刷填充偏移区域;
- grahpics.Clear(Color(255, 192, 192, 192));
- SolidBrush brushWhite(Color(255, 255, 255, 255));
- grahpics.FillRectangle(&brushWhite, 1, 1, THUMBNAIL_WIDTH - 2, THUMBNAIL_HEIGHT - 2);
- // 再将png缩放到背景图中;
- grahpics.DrawImage(pImage, Rect(rcZoom.left, rcZoom.top, rcZoom.Width(), rcZoom.Height()), 0, 0, pImage->GetWidth(), pImage->GetHeight(), UnitPixel);
- // 往list里添加项,先创建Imagelist位图;
- HBITMAP hbmp;
- CBitmap bitmap;
- pZoomImage->GetHBITMAP(Color(255, 255, 255, 255), &hbmp);
- bitmap.Attach(hbmp);
- // 将位图添加到ImageList中;
- m_ImageListThumb.Add(&bitmap, RGB(255,255,255));
- INT nSize = m_ListPNG.GetItemCount();
- m_ListPNG.SetRedraw(FALSE);
- m_ListPNG.InsertItem(nSize, strImageName, nSize);
- m_ListPNG.SetRedraw(TRUE);
- m_ListPNG.RedrawItems(nSize, nSize);
- if (pZoomImage)
- delete pZoomImage;
- if (pImage)
- delete pImage;
- }
- }
- BOOL CDlgRenderings::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
- {
- // TODO: 在此添加消息处理程序代码和/或调用默认值
- if (m_nSelectPNGPosition >= 0 && m_nSelectJPGPosition >= 0)
- {
- ScreenToClient(&pt);
- INT nAlphaIndex = IsPointInAlphaRect(pt);
- if (nAlphaIndex != -1)
- {
- vector<STOffSetInfo>::iterator it = m_vtOffSetInfo.begin();
- for (; it != m_vtOffSetInfo.end(); it++)
- {
- if (it->nIndexOfAlpha == nAlphaIndex)
- {
- break;
- }
- }
- if (it == m_vtOffSetInfo.end())
- return FALSE;
- if (zDelta > 0)
- {// 放大;
- it->fScale -= 0.1;
- }
- else
- {// 缩小;
- it->fScale += 0.1;
- }
- LoadJPGImageSuperEx(nAlphaIndex, it->pImage, it->fScale, it->nXOffSet, it->nYOffSet);
- }
- }
- return CDialog::OnMouseWheel(nFlags, zDelta, pt);
- }
|