Is alphadrawing to bitmap with memorydc and gcdc on ubuntu broken?

Hello,

im trying to draw to a bitmap in memory. This bitmap is then in the PAINT Event drawn
to a Panels PaintDC. The background of the bitmap should be completly transparent.

Code Snippet:

def drawtobuffer(self):
    Size  = self.GetClientSize()
    self.Buffer = wx.EmptyBitmapRGBA(Size.width, Size.height, 0, 0, 0, 0)
    mdc = wx.MemoryDC()
    mdc.SelectObject(self.Buffer)
    dc = wx.GCDC(mdc)
    color = wx.Colour( 35, 142,  35, 128)
    dc.SetBrush(wx.Brush(color))
    dc.SetPen(wx.Pen('CADET BLUE', 2))
    dc.DrawRectangle(50,50,100,50)
    mdc.SelectObject(wx.NullBitmap)
    self.Refresh()

On Ubuntu 12.10 with wxPython 2.9.4.1 gtk2 (classic) the Bitmap is empty. Setting the alpha channel in the line

self.Buffer = wx.EmptyBitmapRGBA(Size.width, Size.height, 0, 0, 0, 128)

to 128 as shown above, the bitmap is no more empty. But the background is opaque.
On Windows7 with wxPython 2.8 everything works fine.

···

Sorry. Iam forget the minimal sample app.

alpadrawing.py (2.35 KB)

Ralf Werner wrote:

Hello,

im trying to draw to a bitmap in memory. This bitmap is then in the
PAINT Event drawn
to a Panels PaintDC. The background of the bitmap should be completly
transparent.

Code Snippet:

def drawtobuffer(self):
Size = self.GetClientSize()
self.Buffer = wx.EmptyBitmapRGBA(Size.width, Size.height, 0, 0, 0, 0)
mdc = wx.MemoryDC()
mdc.SelectObject(self.Buffer)
dc = wx.GCDC(mdc)
color = wx.Colour( 35, 142, 35, 128)
dc.SetBrush(wx.Brush(color))
dc.SetPen(wx.Pen('CADET BLUE', 2))
dc.DrawRectangle(50,50,100,50)
mdc.SelectObject(wx.NullBitmap)
self.Refresh()

On Ubuntu 12.10 with wxPython 2.9.4.1 gtk2 (classic) the Bitmap is
empty. Setting the alpha channel in the line

self.Buffer = wx.EmptyBitmapRGBA(Size.width, Size.height, 0, 0, 0, 128)

to 128 as shown above, the bitmap is no more empty. But the background
is opaque.
On Windows7 with wxPython 2.8 everything works fine.

Using dc.Clear instead of initializing the bitmap with the transparent alpha value seems to work a little better, but it looks like it is still not making the background transparent, or at least it is not drawing it that way. You should probably create a ticket about this at trac.wxwidgets.org.

     def drawtobuffer(self):
         Size = self.GetClientSize()
         self.Buffer = wx.EmptyBitmap(Size.width, Size.height, 32)
         mdc = wx.MemoryDC()
         mdc.SelectObject(self.Buffer)
         dc = wx.GCDC(mdc)

         dc.SetBackground(wx.Brush(wx.Colour(0,0,0,128)))
         dc.Clear()

         color = wx.Colour( 35, 142, 35, 128)
         dc.SetBrush(wx.Brush(color))
         dc.SetPen(wx.Pen('CADET BLUE', 2))
         dc.DrawRectangle(50,50,100,50)
         mdc.SelectObject(wx.NullBitmap)
         self.Refresh()

···

--
Robin Dunn
Software Craftsman

Hello,

Using dc.Clear instead of initializing the bitmap with the transparent
alpha value seems to work a little better, but it looks like it is still
not making the background transparent, or at least it is not drawing it
that way.

Iam tryed your suggestion. But this way the background is not cleared.
This means i get random data as background. Maybe another error?

You should probably create a ticket about this at
>trac.wxwidgets.org.

I opened a bug report:
Ticket #15113

Ralf Werner wrote:

Hello,

     >Using dc.Clear instead of initializing the bitmap with the
    transparent
     >alpha value seems to work a little better, but it looks like it is
    still
     >not making the background transparent, or at least it is not
    drawing it
     >that way.

Iam tryed your suggestion. But this way the background is not cleared.
This means i get random data as background. Maybe another error?

Did you also add the lines that set the background brush and call dc.Clear()?

     >You should probably create a ticket about this at
     >trac.wxwidgets.org <http://trac.wxwidgets.org>.

I opened a bug report:
Ticket #15113 <wxTrac has been migrated to GitHub Issues - wxWidgets;

Thanks. I've added some comments.

···

--
Robin Dunn
Software Craftsman

Hello,

Did you also add the lines that set the background brush and call
dc.Clear()?

Yes. Iam replaced the complete routine in my sample.

Ralf Werner wrote:

Hello,

     >Did you also add the lines that set the background brush and call
     >dc.Clear()?

Yes. Iam replaced the complete routine in my sample.

The Clear should have gotten rid of the random garbage that was in the uninitialized bitmap, but maybe I'm missing something...

···

--
Robin Dunn
Software Craftsman