Resizing image to panel size

I’m trying to display an image in a panel which resizes itself to fit inside. So far what I’m doing is:

  • Create a subclass of panel

  • Open an image as a PIL Image

  • Bind EVT_SIZE and EVT_PAINT to self.OnSize and self.OnPaint

  • In self.OnSize dimensions of the image is calculated. The PIL Image is resized using Image.resize() with BILINEAR/BICUBIC/ANTIALIAS then converted to a wxImage then wxBitmap. Then I refresh the panel

  • The OnPaint method creates a wxBufferedPaintDC and then draws the bitmap to it

My problem is that the image resizing is quite laggy. If I resize the frame, the image will ‘skip’ rather than grow/reduce smoothly. I’ve determined that the resizing of the PIL Image is causing the lag. ANTIALIAS is the slowest while NEAREST is nearly the speed I want.

Is there any way to speed up the image resizing? Or, is there a better way of displaying an image like this? I want it to perform like most common image viewers like Irfanview or the Windows built-in image viewer.

David Yan wrote:

I'm trying to display an image in a panel which resizes itself to fit inside. So far what I'm doing is:

- Create a subclass of panel
- Open an image as a PIL Image
- Bind EVT_SIZE and EVT_PAINT to self.OnSize and self.OnPaint
- In self.OnSize dimensions of the image is calculated. The PIL Image is resized using Image.resize() with BILINEAR/BICUBIC/ANTIALIAS then converted to a wxImage then wxBitmap. Then I refresh the panel
- The OnPaint method creates a wxBufferedPaintDC and then draws the bitmap to it

My problem is that the image resizing is quite laggy. If I resize the frame, the image will 'skip' rather than grow/reduce smoothly. I've determined that the resizing of the PIL Image is causing the lag. ANTIALIAS is the slowest while NEAREST is nearly the speed I want.

Is there any way to speed up the image resizing? Or, is there a better way of displaying an image like this? I want it to perform like most common image viewers like Irfanview or the Windows built-in image viewer.

I don't know if this will help or not, but it looks like this fellow got some good results using numpy / scipy somehow:

http://eigenclass.org/hiki/seam-carving-in-ocaml

I think Barker has mentioned his floatcanvas as being good for image manipulation too, so you might take a look at that as well.

···

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org

__________ Information from ESET NOD32 Antivirus, version of virus signature database 4020 (20090420) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com