Bitmap + Clipboard + Transparency = Blue Background?
-
Hey folks, I think this is my first time asking a question here, so please go easy on me ;) I have an application wherein I render a transparent bitmap (to be specific -- a chart with a transparent background).... When I do, I then try to copy it to the clipboard using:
bmp.Save(filename); // Save to FS Clipboard.SetImage(bmp); // Save to Clipboard
Now if I open Excel, and click Paste (from the clipboard), I end up with a copy of my chart with this lovely blue background wherever the transparency color was. If I, instead, use Excel's Insert->Image->From File, the chart's transparency is preserved... (same bitmap as above, just one is saved to file system, the other is copied via clipboard) What gives? Am I copying the bitmap incorrectly, or is there something else I need to do to make copy and paste of transparent bitmaps a reality? (I have searched high and low, and nothing seems to answer this question... I have tried all kinds of things to resolve this on my own, even using MakeTransparent() (which has no effect, since the bitmap was already transparent to begin with (as evidenced by the Flags value on the bitmap being "2" which is hasTransparency)... I have tried converting the image, using color maps, using SetClipboardDataObject, converting to an HBITMAP object or whatever.... all kinds of things, nothing seems to avert this issue....) Thanks in Advance!============================= I'm a developer, he's a developer, she's a developer, Wouldn'tcha like to be a developer too?
-
Hey folks, I think this is my first time asking a question here, so please go easy on me ;) I have an application wherein I render a transparent bitmap (to be specific -- a chart with a transparent background).... When I do, I then try to copy it to the clipboard using:
bmp.Save(filename); // Save to FS Clipboard.SetImage(bmp); // Save to Clipboard
Now if I open Excel, and click Paste (from the clipboard), I end up with a copy of my chart with this lovely blue background wherever the transparency color was. If I, instead, use Excel's Insert->Image->From File, the chart's transparency is preserved... (same bitmap as above, just one is saved to file system, the other is copied via clipboard) What gives? Am I copying the bitmap incorrectly, or is there something else I need to do to make copy and paste of transparent bitmaps a reality? (I have searched high and low, and nothing seems to answer this question... I have tried all kinds of things to resolve this on my own, even using MakeTransparent() (which has no effect, since the bitmap was already transparent to begin with (as evidenced by the Flags value on the bitmap being "2" which is hasTransparency)... I have tried converting the image, using color maps, using SetClipboardDataObject, converting to an HBITMAP object or whatever.... all kinds of things, nothing seems to avert this issue....) Thanks in Advance!============================= I'm a developer, he's a developer, she's a developer, Wouldn'tcha like to be a developer too?
Transparency is only supported by some file formats, such as PNG. The raw BITMAP format, which is what Windows uses internally, does not support transparency. The Bitmap class does allow setting a color that is transparent, I *think* ( it may be that the support only exists at the point of drawing the image ), but ultimately I suspect what you're finding is that the clipboard contains a raw image, not an image in, say, PNG format. That's if Excel can work it out. More likely, an image in the clipboard is a plain vanilla bitmap, and the image when loaded by Excel, is loaded as a PNG or other format with transparency support, and thus it's respected by Excel, because it's still there.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )