wx.MemoryDC & transparency

161 views
Skip to first unread message

Bart

unread,
Jun 16, 2009, 12:59:57 PM6/16/09
to wxPython-users
Hello,

I use wx.MemoryDC to draw on a empty wx.Bitmap
(wx.EmptyImage.ConvertToBitmap()).
Is it possible to make the entire canvas of the wx.Bitmap transparent?
And from there start drawing things on it?

So the goal is to get a transparent background, and when I put the
wx.bitmap (using wx.StaticBitmap) on a panel with a GradientFill
background the outline of the bitmap doesn't show. Only the stuff that
has been drawn on it after setting the background to transparent.

Thanks in advance!

Bart Smeets

Robin Dunn

unread,
Jun 17, 2009, 4:28:45 PM6/17/09
to wxPytho...@googlegroups.com
Bart wrote:
> Hello,
>
> I use wx.MemoryDC to draw on a empty wx.Bitmap
> (wx.EmptyImage.ConvertToBitmap()).
> Is it possible to make the entire canvas of the wx.Bitmap transparent?
> And from there start drawing things on it?

Depending on platform the wx.MemoryDC may or may not have any clue about
the bitmap's alpha channel (for example, on Windows the wx.DC classes
are all based on pre-alpha APIs,) so the behavior is pretty much
undefined. However if you use the memory DC as the target of a
wx.GraphicsContext then you can get it to honor the bitmap's alpha
channel and blend properly.

>
> So the goal is to get a transparent background, and when I put the
> wx.bitmap (using wx.StaticBitmap) on a panel with a GradientFill
> background the outline of the bitmap doesn't show. Only the stuff that
> has been drawn on it after setting the background to transparent.

This is actually a different problem. The issue here is that since a
wx.StaticBitmap is an independent widget then it has its own window
background, and when it draws the bitmap on itself then that background
is still there, and the parent's background is clipped. (In this
specific case it is mainly just Windows that behaves this way, Mac and
GTK do deal pretty well with transparencies in the static widget types.)
If you want the bitmap to appear to be blended with the parent then I
would go ahead and draw it directly on the parent and don't use the
wx.StaticBitmap.

--
Robin Dunn
Software Craftsman
http://wxPython.org

Bart

unread,
Jun 20, 2009, 7:25:24 AM6/20/09
to wxPython-users
Robin,

Thanks a lot for the detailed information.

Regards,
Bart Smeets
Reply all
Reply to author
Forward
0 new messages