Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have these code for save a gif file:
C++
friend std::ostream& operator << (std::ostream& lhs, image& rhs)
   {
       //Create an empty IStream:
       IStream* pIStream = nullptr;
       if(CreateStreamOnHGlobal(NULL, FALSE, (LPSTREAM*)&pIStream)!=S_OK)
           DebugText("error on creating an empty IStream");

       //Create the Encoder way:
       //choose image format for save it on IStream:
       // Get encoder class id for jpg compression
       // for other compressions use
       //    image/bmp
       //    image/jpeg
       //    image/gif
       //    image/tiff
       //    image/png
       CLSID pngClsid;
       GetEncoderClsid(L"image/gif", &pngClsid);

       // Setup encoder parameters
       EncoderParameters* encoderParameters = (EncoderParameters*)malloc(sizeof(EncoderParameters) +  (rhs.framecount-1)* sizeof(EncoderParameter));
       encoderParameters->Count = 1;
       ULONG parameterValue = 50;
      // the for loop is pointless and does nothing
       encoderParameters->Parameter[0].Guid = EncoderSaveFlag;
       encoderParameters->Parameter[0].Type = EncoderParameterValueTypeLong;
       encoderParameters->Parameter[0].NumberOfValues = 1;
       encoderParameters->Parameter[0].Value = ¶meterValue;

       //save the 1st frame:
       parameterValue = EncoderValueMultiFrame;
       Status            stat;
       rhs.img->SetPalette(rhs.imgPallet);
       if(rhs.img->Save(pIStream, &pngClsid, encoderParameters) != Ok)
       {
           pIStream->Release();
           MessageBox("error on saving to IStream");
       }

       for(int i=1; i

the file is saved, but the backcolor is changed(automatic). maybe because it's transparent. i don't know. can anyone advice me?

What I have tried:

i had tryied use the Palette, but without sucess :(
Posted
Updated 6-Dec-16 1:30am

1 solution

You must set the transparent color in the original picture or in the encoder if possible.

I found another solution on MSDN.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900