Bug in wx.lib.wxcairo.ImageSurfaceFromBitmap with 24bpp images

I think there's a bug with wx.lib.wxcairo.ImageSurfaceFromBitmap; it
doesn't work for 24bpp images.

A simple way to show the bug is to open the Cairo demo and change line 103 from

bmp = wx.Bitmap(opj('bitmaps/toucan.png'))

to

bmp = wx.Bitmap(opj('bitmaps/splash.png'))

(or any other 24bpp image)

This is the exception thrown:

Traceback (most recent call last):
  File "C:\Documents and Settings\Conrado\Dados de
aplicativos\wxPyDemo\modified\Cairo.py", line 31, in OnPaint
    self.Render(dc)
  File "C:\Documents and Settings\Conrado\Dados de
aplicativos\wxPyDemo\modified\Cairo.py", line 104, in Render
    img = wx.lib.wxcairo.ImageSurfaceFromBitmap(bmp)
  File "C:\Python26\Lib\site-packages\wx-2.8-msw-unicode\wx\lib\wxcairo.py",
line 216, in ImageSurfaceFromBitmap
    bitmap.CopyToBuffer(surface.get_data(), fmt, stride)
  File "C:\Python26\Lib\site-packages\wx-2.8-msw-unicode\wx\_gdi.py",
line 765, in CopyToBuffer
    return _gdi_.Bitmap_CopyToBuffer(*args, **kwargs)
RuntimeError: Failed to gain raw access to bitmap data.

Environment:
wxPython 2.8.10.1 on Windows XP SP3

Can anyone confirm this?

Thanks,
Conrado

Yes, I've confirmed it and will work on a fix.

Robin

···

On Jun 6, 5:13 pm, Conrado Porto Lopes Gouvêa <conrado...@gmail.com> wrote:

I think there's a bug with wx.lib.wxcairo.ImageSurfaceFromBitmap; it
doesn't work for 24bpp images.

Can anyone confirm this?

Hi Robin,

I'm getting "RuntimeError: Failed to gain raw access to bitmap data."
when I zoom in on a matplotlib image displaying in WX with shaded
plots.

Any new info on this error or a fix?

thanks

Kevin

···

On Jun 8, 11:58 am, Robin Dunn <ro...@alldunn.com> wrote:

On Jun 6, 5:13 pm, Conrado Porto Lopes Gouvêa <conrado...@gmail.com> > wrote:

> I think there's a bug with wx.lib.wxcairo.ImageSurfaceFromBitmap; it
> doesn't work for 24bpp images.

> Can anyone confirm this?

Yes, I've confirmed it and will work on a fix.

Robin

Kevin wrote:

Hi Robin,

I'm getting "RuntimeError: Failed to gain raw access to bitmap data."
when I zoom in on a matplotlib image displaying in WX with shaded
plots.

Any new info on this error or a fix?

I've committed the fix for the problem described in the previous emails, but without more information I can't tell if this is the same problem or not.

···

--
Robin Dunn
Software Craftsman