[wxpython-users] Re: The new StaticBitmap is dead, long live the old StaticBitmap!

Robin Dunn robin at alldunn.com
Tue Apr 1 10:18:48 PDT 2008


Alex wrote:
> Tim van der Leeuw <tnleeuw <at> gmail.com> writes:
> 
>> Could you perhaps show us some sample-code? (I had no problem creating a
>> Static Bitmap from an Image created from PIL, the other day, using Vista +
>> wxPython 2.8.7.1)Cheers,--Tim
> 
> Sure.
> ----------------------------------------------------------------------------
> #!/usr/bin/env python
> # -*- coding:utf-8 -*-
> 
> import wx
> 
> import wx.lib.inspection
> 
> app = wx.App(redirect=True,filename='debug.log')
> 
> frame = wx.Frame(None, -1, 'simple.py', size=(200,200))
> panel = wx.Panel(frame)
> bmp = wx.EmptyBitmap(200,200,-1)
> pixels = wx.AlphaPixelData(bmp)
> for pixel in pixels:
>     pixel.Set(100,100,0,128)
> static = wx.StaticBitmap(parent=panel, bitmap=bmp)
> frame.Show()
> wx.lib.inspection.InspectionTool().Show() 
> 
> app.MainLoop()
> -----------------------------------------------------------------------------
> 
> Using wx.NativePixelData gives me an error, because apparently,
> wx.NativePixelData chokes on wx.Bitmap-s. I tried wx.NativePixelData because at
> first I thought that winXP somehow disliked the presence of an alpha channel,
> but as I remember winXP could deal OK with alphas.

The raw bitmap access methods work best if you are explicit about the 
bit depth you are using in your bitmaps.  So for wx.NativePixelData try 
using 24 for the 3rd parameter to wx.EmptyBitmap instead of -1.  For 
wx.AlphaPixelData use 32.


-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!



More information about the wxpython-users mailing list