[Qt-interest] Fast Scaling of Images

TP wingusr at gmail.com
Sat Apr 16 16:43:38 CEST 2011


On Fri, Apr 15, 2011 at 10:32 AM, Joshua Grauman <jnfo-c at grauman.com> wrote:
> Hello all,
>
> I'd like to include a simple image viewer in my application to view
> several pngs (around 2000 x 3000 resolution), viewed roughly full screen
> (ie. 1000 x 700 or so). I'd like to user to be able to zoom in/out and
> pan/scroll. I've seen some examples that simply use a QScrollArea with a
> QLabel to display the image. This works fine for me, but I was wondering
> if there might be a better method that would scale the images faster so
> that zoom in/out would be smoother. The examples I've seen simply use
> QLabel::resize() to do the scaling. Is this about as good as I'll get, or
> would there be a noticably faster method (reimplementing QPaintEvent??)?
> Obviously, I could cache several zoom sizes when each image is loaded, I'm
> still thinking if that would be worth it. For now I'm just seeing if there
> is a significantly faster method for doing the actual zooming than via
> QLabel::resize(). Thoughts? Thanks!
>
> Josh
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>

I've found that the QLabel approach is pretty terrible. The more you
zoom in the slower it takes. Try it yourself with the
C:\Qt\4.7.0\examples\widgets\imageviewer\ example.

A much better idea is to use a QGraphicsView to implement zooming &
panning of a QPixmap. I have an example app that does this at
http://tpgit.github.com/MDIImageViewer/index.html. The QGraphicsView
relevant docs are at
http://tpgit.github.com/MDIImageViewer/imageviewer.html#synchablegraphicsview.

This uses PyQt and thus is written in Python, but it should be pretty
easy to figure out how to do the same thing using C++ & Qt.



More information about the Qt-interest-old mailing list