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

Christopher Barker Chris.Barker at noaa.gov
Tue Apr 1 09:41:26 PDT 2008


Alex wrote:
> Well that seems kinda backward. You see, I can have anywhere from 1 to 30
> small(30px squarish) StaticBitmaps, they're each coupled to a slider, and they
> change color whenever the slider is moved. (The slider represents a position
> over a gradient with up to 256 values). So.. I don't know what's worse, constant
> Raw Pixel Access, or constant drawing on a memoryDC.

I'd expect that just drawing rectangles with a DC would work just fine. 
After all, drawing a rectangle is simply setting a block of pixels to a 
value, and it's all happening in C++ , or even in the graphics card 
itself; you're not going to beat that. Also, by its nature, Raw Pixel 
access opens you up for platform differences -- using a DC should "just 
work" on all platforms.

It may make sense to not use StaticBitmaps, but rather draw each of 
those rectangles yourself with a single DC.

If you do really have a need to work with Raw Pixels, I'd check out 
numpy for that -- it can be really fast. aside from speed, numpy arrays 
can have multiple dimensions, so a RGBA array can be a (w,h,4) array, 
making it easy to set pixels without doing any arithmetic:

# set all pixels alpha value to 122:
ImageArray[:,:,3] = 122

# draw a red semi-transparent 10x10 rectangle ten pixels from the top 
and bottom:
ImageArray[10:20, 10:20, :] = (255, 0, 0, 122)

There are numpy examples in the demo.

-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.Barker at noaa.gov


More information about the wxpython-users mailing list