Click here to Skip to main content
14,238,591 members
Rate this:
Please Sign up or sign in to vote.
See more:
my project have a bitmap.but the bitmap is too big.i want it i change the bitmap format from bmp to gif.than i add this gif to my project as a source.when my program is runing,i want change the picture format from gif to bmp agan.i write a function like tihs:

BOOL CLoadDlg::GIFToBMP(CString& strGIFFile,CString& strBMPFile)
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

CLSID encoderClsid;
GetEncoderClsid(L"image/bmp", &encoderClsid); //i copy the "GetEncoderClsid"function from GDI+ SDK.
//Image image(strGIFFile.AllocSysString());
HRSRC hrsc = FindResource(NULL, MAKEINTRESOURCE(IDR_GIF1), "GIF"); //"IDR_GIF1"is my source-id of GIF .
HGLOBAL hG = LoadResource(NULL, hrsc);
//hG = LockResource(hG);
IStream* pStmImage = NULL;
CreateStreamOnHGlobal(hG, TRUE, &pStmImage);
Image image(pStmImage);

Status stat = image.Save(strBMPFile.AllocSysString(),&encoderClsid,NULL);

if(stat == Ok)
return TRUE;
return FALSE;

but when i call this function,it have no effect...
please help me,where is wrong.
Rate this:
Please Sign up or sign in to vote.

Solution 1

I don't really understand - why do you even need to do this ? A bmp is uncompressed, but a gif, a jpeg, a bmp, etc, all take the same format when they have been loaded in memory.

What do you mean 'have no effect' ? Does the image not get saved ? Is it not a bitmap ? If you had a 24 bit image and you saved it to gif, it's now 8 bit, and so saving to bmp will create a smaller bmp, because of the information that was lost.
Rate this:
Please Sign up or sign in to vote.

Solution 3

Please edit your post instead of posting answers that are really questions.

Have you stepped through the code in your debugger ? Is a file created at all ? Is your resource loading properly ? I would start by replacing your current handle to save with one you load from disc, of the same file. Then work backwards from there. That way you can isolate which piece of code is failing.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100