deepzero Posted April 3, 2011 Posted April 3, 2011 (edited) hi,for quiet some time i am occupied by this little assignment:Take a screenshot, shrink it (while preserving the aspect ration) and save it to disk.my code:int GetEncoderClsid(const WCHAR* format, CLSID* pClsid){ using namespace Gdiplus; 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 pImageCodecInfo = (ImageCodecInfo*)(GlobalAlloc(0,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; GlobalFree(pImageCodecInfo); return j; // Success } } GlobalFree(pImageCodecInfo); return 0;}int main(){ ULONG_PTR m_gdiplusToken; Gdiplus::GdiplusStartupInput gdiplusStartupInput; Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL); Bitmap* bm = new Bitmap(1450,1050,PixelFormat32bppARGB);//create an empty image HDC scrn = GetDC(0);//take screenshot Graphics gr(scrn);//assign it to a graphics object gr.DrawImage(bm,100,100,1450,1050);//shrink it to 100x100 CLSID clsid; GetEncoderClsid(L"image/jpeg", &clsid);//get jpg encoder bm->Save(L"D:\\wtf.jpg",&clsid);//save image return 0;}obviously i am not the greatest gdi+ expert around...but i cant see why this code just fails without any error (image is just not created....) Edited April 3, 2011 by deepzero
Killboy Posted April 3, 2011 Posted April 3, 2011 Looks like you forgot to fill gdiplusStartupInput, at least .GdiplusVersion must be 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now