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.
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.
I actually just made a simple image viewer with wxPython and PIL. I didn't want to, but I was having a hard time finding a viewer as simple as I wanted. Anyway, I started from this page and worked myself up to an app that zooms, rotates, and browses all images in the folder it was started from. When I get home I can post the full code if you like.
I'm new here, and after searching for a while I still can't find a way to upload files. Oh well, here's the code in a post. Sorry for the non-descriptive variable names and lack of comments. I guess the main functions you'll want to look at are processPicture and showPicture.
Edit: and just to reiterate, I started this with the example in this tutorial.
And there is Cornice an open source image viewer written in wxPython which might help you
You can try Document/View architecture. I think it should be available in Python. You can take a look at this tutorial, it is for C++ but approach should be similar. It also shows how to implement selection rectangle.