wx.GraphicsContext @ wx.EmptyBitmapRGBA Linux Bug

This demo app demonstrate offline rendering of bitmaps using
wx.GraphicsContext is buggy.

If you are using wx.EmptyBitmapRGBA(100, 100) to render a bitmap then
bitmap is coming out completely empty. (not event black)

If you are using wx.EmptyBitmap(100, 100) to render a bitmap then
bitmap is full of garbage. (see attached image)

Actually I created this demo app to show that in my application
transparency is replaced by pure black color, eventually I have found
two more problems when I created this app.

The description in demo->Using Images>Image Alpha says something about
this on GTK platform but I am seeing transparency properly on my
machine, means it has been fixed.

class TestPanel(wx.Panel):
    def __init__(self, parent, log):
        self.log = log
        wx.Panel.__init__(self, parent, -1)

        self.prepareOfflineBitmap()
        self.Bind(wx.EVT_PAINT, self.OnPaint)

    def prepareOfflineBitmap(self):
        font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT)
        self.bitmap = wx.EmptyBitmapRGBA(100, 100)#wx.EmptyBitmap(100,
100)
        mdc = wx.MemoryDC(self.bitmap)
        ctx = wx.GraphicsContext.Create(mdc)
        ctx.DrawText("wxPython Rocks!!!", 0, 45)
        ctx.SetBrush(wx.Brush("red"))
        ctx.DrawRectangle(10,10,25,25)
        mdc.SelectObject(wx.NullBitmap)
        del mdc

    def OnPaint(self, evt):
        dc = wx.PaintDC(self)
        gc = wx.GraphicsContext.Create(dc)

        gc.PushState()
        gc.Translate(0,0)
        gc.DrawBitmap(self.bitmap, 0, 0, 100, 100)
        gc.PopState()

You can use demo app to run this application. I ripped the code from
demo->Miscellaneous->GraphicsContext.

Prashant

Note: I am not able to send mails from my mail account and keep
getting failure notice.
          Cannot post hyper link of image. Post is getting rejected
may be you can get the same
          results from the code.

#---- System Information ----#
GUI2Exe Version: 0.5.0
Operating System: Linux 2.6.31-14-generic i686
Python Version: 2.6.4rc2 (r264rc2:75497, Oct 20 2009, 02:55:11)
[GCC 4.4.1]
wxPython Version: 2.8.10.1 (gtk2-unicode)
wxPython Info: (__WXGTK__, wxGTK, unicode, gtk2, wx-assertions-off,
SWIG-1.3.29)
Python Encoding: Default=UTF-8 File=UTF-8
wxPython Encoding: utf-8
System Architecture: 32bit i686
Byte order: little
Frozen: False
#---- End System Information ----#

This demo app demonstrate offline rendering of bitmaps using
wx.GraphicsContext is buggy.

If you are using wx.EmptyBitmapRGBA(100, 100) to render a bitmap then
bitmap is coming out completely empty. (not event black)

Because the all the alpha values in the image are marked as fully transparent when you create it and the transparency is not being modified when you draw on it. This is a known problem on wxGTK.

If you are using wx.EmptyBitmap(100, 100) to render a bitmap then
bitmap is full of garbage. (see attached image)

Because the memory used for the bitmap is not initialized when the bitmap is created. You should always set a background brush and Clear() the first time you use a bitmap in a memory DC.

Note: I am not able to send mails from my mail account and keep
getting failure notice.
           Cannot post hyper link of image. Post is getting rejected

Are you sending the file as an attachment or just trying to embed it in the text of your email? If so then try it as an attachment, or try a different mail client.

···

On 2/11/10 3:59 AM, King wrote:

--
Robin Dunn
Software Craftsman

Do we have any hack to solve this?

I tried to create a bitmap like this:

wx.EmptyBitmapRGBA(100, 100, 1, 1, 1, 255)

Now this is not a bitmap with default transparency because r,g,b,a are
initialized at the time of creation.
Once drawing to bitmap is finsihed I tried to mask the color (1,1,1)

mask = wx.Mask(bitmap, wx.Colour(1,1,1))
bitmap.SetMask(mask)

apparently this trick also failed.

If there is any other trick that may solved this problem then please
let me know.

Thanks

Prashant

···

On Feb 11, 6:45 pm, Robin Dunn <ro...@alldunn.com> wrote:

Because the all the alpha values in the image are marked as fully
transparent when you create it and the transparency is not being
modified when you draw on it. This is a known problem on wxGTK.