GDIPLUS::Image::Save(IStream*): why change the backcolor?

see how i can save a gif file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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 = &parameterValue;

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

        for(int i=1; i<rhs.framecount;i++)
        {
            //create a new Image for save the selected frame:
            Image *img2= rhs.img;

            //Selecte the frame:
            UINT count = 0;
            count = img2->GetFrameDimensionsCount();
            vector<GUID> pDimensionIDs;
            pDimensionIDs.resize(count);
            img2->GetFrameDimensionsList(pDimensionIDs.data(), pDimensionIDs.size());
            img2->SelectActiveFrame(&pDimensionIDs[0],i);

            //save the next frames, from img2, on stream:
            if(i==rhs.framecount-1)
                parameterValue = EncoderValueLastFrame;
            else
                parameterValue = EncoderValueFrameDimensionTime;
            stat = rhs.img->SaveAdd(img2, encoderParameters);
        }
        //closing the stream:
        parameterValue = EncoderValueFlush;
        stat = rhs.img->SaveAdd(encoderParameters);

        //getting the stream size:
        STATSTG sts;
        pIStream->Stat(&sts, STATFLAG_DEFAULT);
        ULARGE_INTEGER uli = sts.cbSize;
        LARGE_INTEGER zero;
        zero.QuadPart = 0;
        int size = (int)uli.QuadPart;

        //save the stream to char*
        char* bits = new char[size];
        ULONG written;
        pIStream->Seek(zero, STREAM_SEEK_SET, NULL);
        pIStream->Read(bits, size, &written);

        if(rhs.blnSaveFile!=true)
        {
            //write the stream size on file
            lhs.write(reinterpret_cast<char*>(&size),sizeof(int));
        }

        //write pBuff data on file
        lhs.write(reinterpret_cast<char*>(bits),size);

        //clean resources
        delete[] bits;
        pIStream->Release();
        free(encoderParameters);

        return lhs;
    }

the file is save. the animated too. but the problem is: why the backcolor is changed from white to black?(doing these, i can lose some pixels :( )
Topic archived. No new replies allowed.