Emptybitmap not transparent on Mac?

30 views
Skip to first unread message

Paul Sijben

unread,
Dec 15, 2009, 10:39:31 AM12/15/09
to wxpytho...@googlegroups.com
I have some code that will generate a transparent bitmap with in it a combination of two other bitmaps (see code below). This works great on both linux and windows, however on the Mac the resulting bitmap is not transparent but has an ugly black background.
Can someone please tell me what I need to change to make this work on the mac?

Paul

    def BitmapOnBitmap(self,icon1,icon2,offset=(4,4),parent=None):
        x,y=offset
        w= x+16+2
        h= y+16+2

        bitmap=wx.EmptyBitmap(w,h)
        if parent:
            bg=parent.GetBackgroundColour()
        else:
            bg=wx.CYAN

        bgbrush=wx.Brush(bg,wx.TRANSPARENT)
        scratch=wx.MemoryDC(bitmap)
        scratch.SetBackground(bgbrush)
        scratch.Clear()
        scratch.DrawBitmap(self.images[icon1],0,0)
        scratch.DrawBitmapPoint(self.images[icon2],offset)
        scratch.SelectObject(wx.NullBitmap)
        bitmap.SetMask(wx.Mask(bitmap,bg))
        return bitmap


--

perzonae logo Paul Sijben tel: +31 33 7114626
Perzonae Unified Communications BV mobile: +31 646272086
Amersfoort, the Netherlands www.perzonae.com


Christopher Barker

unread,
Dec 15, 2009, 12:08:36 PM12/15/09
to wxpytho...@googlegroups.com
Paul Sijben wrote:
> I have some code that will generate a transparent bitmap with in it a
> combination of two other bitmaps (see code below). This works great on
> both linux and windows, however on the Mac the resulting bitmap is not
> transparent but has an ugly black background.
> Can someone please tell me what I need to change to make this work on
> the mac?

try using:

wx.EmptyBitmapRGBA

instead of wx.EmptyBitmap

if that doesn't do it:

http://wiki.wxpython.org/MakingSampleApps

and post again, and I'll test some stuff out.

-Chris


--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris....@noaa.gov

Robin Dunn

unread,
Dec 15, 2009, 1:21:36 PM12/15/09
to wxpytho...@googlegroups.com
On 12/15/09 7:39 AM, Paul Sijben wrote:
> I have some code that will generate a transparent bitmap with in it a
> combination of two other bitmaps (see code below). This works great on
> both linux and windows, however on the Mac the resulting bitmap is not
> transparent but has an ugly black background.
> Can someone please tell me what I need to change to make this work on
> the mac?

> bgbrush=wx.Brush(bg,wx.TRANSPARENT)

If there is a bug here it is with wxGTK and wxMSW because a transparent
brush is not supposed to actually draw anything. In other words, its
transparency is not due to it drawing in such a way that a mask or alpha
channel is set, but because it doesn't touch the pixels that are already
there. Apparrently if a valid colour is also set on GTK and MSW then
that is taking precedence, but on Mac the style is overriding the colour.

To fix this all you should need to do is not use the wx.TRANSPARENT
style. You'll get your transparency later when you set the mask.

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

Paul Sijben

unread,
Dec 16, 2009, 4:27:45 AM12/16/09
to wxpytho...@googlegroups.com
Robin,

thanks that solved it!

Paul
--
Reply all
Reply to author
Forward
0 new messages