int Getencoderclsid (const wchar* format, clsid* pclsid) { UINT num = 0; Number of Image encoders UINT size = 0; Size of the image encoder array in bytes
imagecodecinfo* pimagecodecinfo = NULL;
Getimageencoderssize (&num, &size); if (size = = 0) return-1; Failure www.111cn.net
Pimagecodecinfo = (imagecodecinfo*) (malloc (size)); if (Pimagecodecinfo = NULL) return-1; Failure
Getimageencoders (num, size, pimagecodecinfo);
for (UINT j = 0; j < num; ++j) { if (wcscmp (PIMAGECODECINFO[J). MimeType, format) = = 0) { *pclsid = Pimagecodecinfo[j]. Clsid; Free (pimagecodecinfo); Return J; Success } }
Free (pimagecodecinfo); return-1; Failure }
void Drawmainwindow (image* img,int w,int h) { HDC HDC = GetDC (AfxGetMainWnd ()->m_hwnd); if (HDC) { Graphics Graphics (HDC); Graphics. DrawImage (Img,w,h,img->getwidth (), Img->getheight ()); ReleaseDC (AfxGetMainWnd ()->M_HWND,HDC); }
}
void GetThumbnail (LPCSTR srcfile,lpcstr dstfile,int width,int height,bool) { Gdiplusstartupinput Gdiplusstartupinput; ULONG_PTR Gdiplustoken; Gdiplusstartup (&gdiplustoken,&gdiplusstartupinput,null);
Uses_conversion; Image srcimage (a2w (srcfile)); Image *dstimage;
int srcwidth = Srcimage.getwidth (); int srcheight = Srcimage.getheight ();
if (constratio) { if (Width/srcwidth < height/srcheight) { Height = width * srcheight/srcwidth; } else { width = height * srcwidth/srcheight; } } Dstimage = Srcimage.getthumbnailimage (width,height);
CLSID Imgclsid; Getencoderclsid (L "Image/jpeg", &imgclsid); Dstimage->save (a2w (dstfile), &imgclsid,null);
Drawmainwindow (&srcimage,0,0); Drawmainwindow (Dstimage,0,srcimage.getheight () +10); Delete Dstimage; Dstimage = NULL;
Gdiplusshutdown (Gdiplustoken); } |