how to create a transparent background color in wx.Bitmap?

I can create a GIF image in a paint program and set one of the colors to act as a transparent background color. wxWidgets 2.5.x also supports alpha channel information in PNG images, but I don't have a paint program on my Mac or Windows box that let's me generate a PNG file with that information, so I can't test it. If someone wants to suggest a free paint program that I should try that can open and save PNG images including alpha channel info I'll give that a shot.

But my real question is whether I can set a transparent background color in a wx.Image or wx.Bitmap that I create dynamically? If it is possible, I would like to see an example code snippet, say creating a filled circle on a background color that will be set as transparent.

Then I can set that bitmap to be used as the image with a wx.StaticBitmap for some experiments I'm doing animating sprites. Right now I'm just doing all my drawing and animating with a double-buffered bitmap canvas, and I've done a another sample using an image loaded from a file, and I plan to try it with FloatCanvas as well. But in order to do more with the StaticBitmap control I need to be able to generate and set the image with a transparent background on the fly. I suppose I could do it with PIL, but I would like it to be pure wxPython if possible.

For those that care about this sort of thing, what I'm working on is porting some Flash animation examples to Python using PythonCard.

http://www.bit-101.com/index2.php
http://www.bit-101.com/tutorials/

So far I've just done the gravity tutorial as a proof-of-concept which works fine. The biggest problem is that I need Anti-Grain Geometry (AGG) wrapped in Python so that the images look better (alpha channels and anti-aliased).

http://www.antigrain.com/

For those that are using PythonCard and want to do a checkout from cvs to get the dependencies, the code is at:

http://cvs.sourceforge.net/viewcvs.py/pythoncard/PythonCard/samples/gravity/

ka

I belive The Gimp supports what you want, and it is available for Win.

···

On Mon, 27 Sep 2004 09:23:46 -0700, Kevin Altis <altis@semi-retired.com> wrote:

I can create a GIF image in a paint program and set one of the colors
to act as a transparent background color. wxWidgets 2.5.x also supports
alpha channel information in PNG images, but I don't have a paint
program on my Mac or Windows box that let's me generate a PNG file with
that information, so I can't test it. If someone wants to suggest a
free paint program that I should try that can open and save PNG images
including alpha channel info I'll give that a shot.

--
Regards,

    Jeff

Kevin Altis wrote:

I can create a GIF image in a paint program and set one of the colors to act as a transparent background color. wxWidgets 2.5.x also supports alpha channel information in PNG images, but I don't have a paint program on my Mac or Windows box that let's me generate a PNG file with that information, so I can't test it. If someone wants to suggest a free paint program that I should try that can open and save PNG images including alpha channel info I'll give that a shot.

But my real question is whether I can set a transparent background color in a wx.Image or wx.Bitmap that I create dynamically? If it is possible, I would like to see an example code snippet, say creating a filled circle on a background color that will be set as transparent.

  f = wx.Frame(None)
  w = wx.Window(f)
  f.Show()
  b = wx.EmptyBitmap(50,50)
  dc = wx.MemoryDC()
  dc.SelectObject(b)
  dc.SetBackground(wx.Brush("black"))
  dc.Clear()
  dc.SetBrush(wx.Brush("blue"))
  dc.SetPen(wx.Pen("red", 2))
  dc.DrawCircle(25,25, 20)
  dc.SelectObject(wx.NullBitmap)
  b.SetMaskColour("black")
  dc = wx.ClientDC(w)
  dc.DrawBitmap(b, 50,50, True)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!