R – Image viewer – standard gui controls, bottom-up or what


I need to make a basic image viewer.
The main concern is how to implement (in terms of gui components and image manipulation) such features as: zoom in-out, scroll and 'hand tool'.

There seems to be several options for achieving this goal, differing mainly in degree of putting responsibilities on the graphical interface framework as opposed to manually implementing things.

Two solutions that are obvious to me are:

1) Resizing and cropping the visible part of the image is crafted on its own using functionality of some image manipulation library. The image (or it's part) is then drawn on some window/control in an overridden onPaint() method. Scrollbars updating (when 'hand tool' used) and operation (when used directly) code needs to be written.

2) An oversized control (StaticBitmap or whatever) containing the image is put inside a window with automatic scrolling. Then one needs to figure out how to convert image coordinates to scrolling coordinates.

Both ways look awkward. Any ideas how to do it in a neat way? Or is what I feel as being ugly just the only way to go?

I'm using Python with wxPython/wxWidgets and PIL, but the question is to a large extent language- and platform- independent.

Sample code and links to sources (of something that is not too bloated) are welcome.

Best Solution

Here's a tutorial that might help. Build a wxPython Image Viewer

I didn't actually watch all the videos, so I can't speak to how well it address's your specific problems.

Also, here's a blog post by Jeff Atwood on Coding Horror that could apply. Programming Is Hard, Let's Go Shopping! It speaks to when you should take the time to write your own code and when to just use a third party solution.