Could someone give me some direction on how to load/save a gif with transparency using CImage?
Currently I'm loading them and then setting the transparency index using gif header, but can't get them to save correctly at all, even if I rewrite the background color in the header.
Get Secure! - www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights. -------------------- Third-Party Link Disclaimer
This response contains a reference to a third-party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.
Hi Gary, I found that link when I was initially researching the problem. I believe that's a different CImage class.
I've been through the ATL code, and the bits are copied for the palette, but the alpha bits are not used in the GDI bitmap, and no transparency index initialized.
I'm using:
CImage img; img.Load(picPath);
to load the bitmap. If it's a gif, I grab the header and info block from the file and use img.SetTransparentColor (...) set to the background color field value if the packed field indicates it's valid.
To save I was trying to do essentially the same, after the img.save(tempPath), I write the packed field to indicate the tranparency is valid by using | 0x80, and set the background color field, but it doesn't work. I've confirmed the changes are written. At present I'm attempting to use Gdiplus::Bitmap.Save(), to see if it supports writing the transparent values, but I need to figure out the encoder parameters first. More header reading.
>Get Secure! - www.microsoft.com/security >This posting is provided "AS IS" with no warranties, and confers no rights. >-------------------- >Third-Party Link Disclaimer
>This response contains a reference to a third-party
World Wide Web site.
>Microsoft is providing this information as a convenience to you. Microsoft >does not control these sites and has not tested any
software or information
>found on these sites; therefore, Microsoft cannot make
any representations
>regarding the quality, safety, or suitability of any software or >information found there. There are inherent dangers in the use of any >software found on the Internet, and Microsoft cautions you to make sure >that you completely understand the risk before
CImage img; img.Load("C:\\some.gif"); LONG tcolor = img.GetTransparentColor();
tcolor will always receive -1 even if the GIF file is set for a transparent background. The problem is also found in PNG files.
The problem is in the ATL CImage Load and Save code. In the Load, it makes a GDI palette without initializing any transparency info, and in the Save, it uses the GDI bitmap's palette which doesn't contain any transparency info. I've bypassed both using my own code based on the GDI+ Image Load and Save and it works fine, so it's obviously supported in the encoder/decoder, just not the ATL CImage code.
This should either be classified as a bug, or ammended in the docs somewhere for the ATL CImage class, since the docs currently note transparency is supported for 4 or 8 bit indexed images, but fail to note it can't load or save them. If you would like the code that fixes it, let me know and I'll make it available on the net.
Thanks and Happy New Year to you too. Scott
>-----Original Message----- >Hi guysmiley
>Thanks for your quickly reply!
>To isolate the problem, I need some code to perform more research on your >program.
>Would you please upload a small self-contained project
which can repro the
>problem on your side if possible and convenience, or a
It seems a problem to the CImage.Load()/Save() method, now I have reported this issue to the product team and waiting for their feedback, perhaps it will need some time. If I get any response, I will reply to you as soon as possible.
And meantime, we will very appreciate if you can share your valuable revised Load()/Save() function code with the community members.
Thanks!
Best regards,
Gary Chang Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights. --------------------
After looking through the atlimage.h file, it appears that the m_iTransparentColor member (which is what is returned after the call to GetTransparentColor() ) is automatically initialized to -1 when the CImage object is created. It The only way we can change that is by calling the SetTransparentColor() function.
So yes, I agree with you that we should notify the product group about this. I will contact them on this problem to see how to document this behavior.
Thanks again for your feedback. If you feel there is any we can do, please feel free to post here.
Best regards, Yanhong Huang Microsoft Community Support
Get Secure! ¨C www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights.
Yan-Hong Huang[MSFT] wrote: > After looking through the atlimage.h file, it appears that the > m_iTransparentColor member (which is what is returned after the call to > GetTransparentColor() ) is automatically initialized to -1 when the CImage > object is created. It The only way we can change that is by calling the > SetTransparentColor() function.
> So yes, I agree with you that we should notify the product group about > this. I will contact them on this problem to see how to document this > behavior.
Has there been any further developments on this issue since a year ago? We've just run into this problem, and I wouldn't mind a Microsoft-sanctioned fix if there is one...
Jonathan Brecher CambridgeSoft Corporation myfirstinitialmylastn...@cambridgesoft.com