tags:

views:

874

answers:

2
Bitmap bff(L"1.jpg");
bff.Save(L"2.jpg", &Gdiplus::ImageFormatJPEG, NULL);

This creates a new file 2.jpg with zero-bytes length. Isn't it supposed to write an image file that is identical to 1.jpg?

Why I'm having zero-bytes length files? I'm doing this test because writing other Bitmaps to files end the same way.

A: 

&Gdiplus::ImageFormatJPEG is the wrong value to send as the second parameter (thus why the new file is zero bytes large). Take a look at the code example at the bottom of the Image::Save() reference page which demonstrates the proper usage of Save().

GRB
When I'm using the code in the sample, the one with GetEncoderClsid, I'm getting an "Invalid Parameter" error. The return value of the method Save is 2. and nothing is written.
Karim
GRB
Also, could it be that JPEG encoder *requires* parameters? You are passing NULL as the third parameter, but could it be that for JPEG encoder the 'quality' setting is non-optional, as in this http://msdn.microsoft.com/en-us/library/ms533844(VS.85).aspx example?
AndreyT
AndreyT: For me, at least, `Save()` runs fine on JPEGs with a NULL third parameter
GRB
+1  A: 

AFAIK, you can't just pass the image format GUID ('ImageFormatJPEG' in your case) to 'Image::Save' method. The second argument is supposed to hold the encoder GUID, not a format GUID. See an example here

AndreyT