StaticBitmap fast refresh state of the art?

I have a wxPython program which displays a large wx.Image and updates it rapidly.

I’ve been using a wx.StaticBitmap for this, but the refresh speed is terrible and there’s a lot of flickering.

From what I can tell by Googling, wx.StaticBitmap is known to be bad for this scenario. In particular, wx.StaticBitmap doesn’t blit and doesn’t double-buffer?

There is lots of advice on the internet about this, and most of it amounts to “roll your own,” using a variety of techniques. I can’t tell which technique is best.

I can make some accommodations for a technique which will get me faster speed. Like, I can use a wx.Bitmap for the input instead of wx.Image. Or I can draw directly to a DC, as long as that DC allows me to use wx.GraphicsContext with alpha blending.

I do need the features of wx.StaticBitmap, in particular I need to change the image size sometimes. My wx.StaticBitmap is inside of a wx.ScrolledPanel so the wx.ScrolledPanel needs to know the size of the image.

What is the state of the art for a fast wx.StaticBitmap?

Also I can’t tell where the source code for wx.StaticBitmap is. Is it this? https://github.com/wxWidgets/Phoenix/blob/3ee614e0e8cd5ed603b6a07f4e5ab846ca9de036/wx/lib/statbmp.py

Ok I see, this is a different component, wx.lib.statbmp.GenStaticBitmap.

wx.lib.statbmp.GenStaticBitmap doesn’t flicker at all, but its refresh speed is slower.

Plenty ideas and findings by your own research. Which is a good start. Welcome to you, James.

Pls attach your current source code and I’m almost certain this community can improve it to your satisfaction.

Thom

Hi James,

As mentioned in the docs of StaticBitmap,

wx.StaticBitmap — wxPython Phoenix 4.2.0 documentation
Native implementations on some platforms are only meant for the display of the small icons in the dialog boxes.

If you have rapidly changing big images, it is better to write your own control with double-buffered DC.

A year ago I posted a benchmark of drawing speed for some packages including wxStaticBitmap.
(Actually, there was no difference in speed between wxStaticBitmap, DC, and double-buffered DC, but only flickering or not):

Comparison of rendering speeds of several toolkits and wx - #3 by komoto48g.

Hope it helps you.

2 Likes

So I’ve improved my program’s rendering performance, and here’s how:

  1. Use GenStaticBitmap instead of StaticBitmap. This eliminates the flickering.
  2. Draw with a gc = wx.GraphicsContext.Create(wx.MemoryDC(bitmap)). This allows me to draw with GraphicsContext commands directly into the wx.Bitmap with no copies. Then I can SetBitmap(bitmap) the GenStaticBitmap.

Great! There seems to be no flicker when using GenStaticBitmap.

But why? The implementation of wx.lib.statbmp.GenStaticBitmap is quite simple and double buffer (BufferedPaintDC) is not used.

Flickering is due to background being erased.

See next method’s OnEraseBackground comment: “This is intentionally empty to reduce flicker.”

1 Like

Oh, thank you! I did not notice it…