Transparent Image? RRS feed

  • Question

  • User-370989946 posted

    I'm trying to draw a totally transparent image - 200 pixels wide and 500 pixels high - all I get is a black image.

    Dim ChartBitMap As Bitmap = New Bitmap(ChartWidth, ChartHeight)Dim ChartGraphics As Graphics = Graphics.FromImage(ChartBitMap)


    ChartBitMap.Save("C://Test_transparent.gif", System.Drawing.Imaging.ImageFormat.Gif)



    Wednesday, December 5, 2007 7:30 AM

All replies

  • User1080017370 posted

    Have a look at http://www.bobpowell.net/giftransparency.htm, where you'll find an explanation of how to do it.

    Wednesday, December 5, 2007 8:00 AM
  • User-370989946 posted

    Hi Robert!

    Thanks for the link - I already had tried to wade through that - but there must be an easier way - All I want is a brand new totally transparent gif of a specific size. I am not trying to change an existing file. This can't be but a few lines of code. I'm obviously new to GDI+, but why doesn't graphics.clear(color.transparent) work as expected?



    Wednesday, December 5, 2007 8:30 AM
  • User294545519 posted

    Hi Gretchen,

    I believe when you do graphics.clear() you are essentially adding a new 'layer' to the image on top of the existing layers. So by adding graphics.clear(color.transparent) its as if its adding a transparent later on top. If you replace transparent with red i believe that will be added on top. So this is why its probably not working how you would expect. 

    Wednesday, December 5, 2007 11:50 AM
  • User-370989946 posted

    Thanks Curt - that makes sense. Does this mean there is no way to 'easily' produce a transparent gif?


    Wednesday, December 5, 2007 12:05 PM
  • User1813517338 posted

    I think what you have will work fine, just make the follwing change:

    Change this: Dim ChartBitMap As Bitmap = New Bitmap(ChartWidth, ChartHeight)  

    TO: Dim ChartBitMap As Bitmap = New Bitmap(ChartWidth, ChartHeight, PixelFormat.Format32bppArgb)


    Thursday, February 19, 2009 11:47 AM