PDA

View Full Version : Clever image zooming. What to write in PaintEvent?



ModeZt
13th December 2007, 00:06
Hello. I'm making a simple image (geographic map) editor for myself.
1) I have a QScrollArea and a custom Widget inserted into the scroll area.
2) I have a large image. 5000x5000 pixels. I read it into a QPixmap.
3) I have a second qpixmap. i put a scaled copy of my image into that pixmap.
in the paintevent of the widget i draw the second pixmap.

The problem is a huge memory usage. For example if i whant a 200% zoom i make a doubled copy of my image and store it in memory together with the original image..

Maybe there's a way to write a more efficient PaintEvent?
Thx.

high_flyer
13th December 2007, 10:38
I think that a better way would be to use the Graphics View framework.
It is optimized in many ways, to handle many, and large items.

Hopefully Andreas (the troll who developed it) will see this thread, and might comment with more details.

ModeZt
15th December 2007, 04:38
Ok. I'm now looking at the QGraphicsScene/View.
I made a


myGraphicsScene->setBackgroundBrush( QBrush( QImage("myimage.bmp") ) );

It works. But when i zoomIn/Out whith myGraphicsView->scale(..) the image resizeing is not smooth.. I mean there's no bilinear filtering and the image looks bad when zoomed in/out.

ModeZt
15th December 2007, 04:48
And i got the same problem with unsmoothed image when i


myGraphicsScene->addPixmap( QPixmap::fromImage(image) );

spud
15th December 2007, 12:02
try
graphicsView->setRenderHint (QPainter::SmoothPixmapTransform);
and/or


QGraphicsPixmapItem* item = myGraphicsScene->addPixmap( QPixmap::fromImage(image) );
item->setTransformationMode(Qt::SmoothTransformation);

and/or

graphicsView->setViewport(new QGLWidget)

ModeZt
15th December 2007, 12:48
many thanx, spud!
this solution works!

QGraphicsPixmapItem* item = addPixmap( QPixmap::fromImage(image) );
item->setTransformationMode(Qt::SmoothTransformation);
( BTW it's not working together with OpenGL viewport )

as mentioned in the http://doc.trolltech.com/4.3/qgraphicspixmapitem.html the result is not as good as QPixmap::scale(), but the performanse boost is huge!

spud
15th December 2007, 13:39
Glad it works!
Just out of curiosity, how does setting the OpenGL viewport fail? In your case OpenGL should give you another huge performance boost, especially on linux systems(because of the way X handles server side pixmaps).

wysota
15th December 2007, 15:20
Just out of curiosity, how does setting the OpenGL viewport fail? In your case OpenGL should give you another huge performance boost, especially on linux systems(because of the way X handles server side pixmaps).
It is probably not smooth. That might need a GLWidget with sample buffers turned on.

ModeZt
16th December 2007, 14:39
It is probably not smooth. That might need a GLWidget with sample buffers turned on.
on both Linux and Win i don't get smoothing if i change the viewport.

graphicsView->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));

but that's not all the troubles i have with OpenGL viewport.
with small images it works nicely, but with the 80 megabytes 5000x5000 bmp it does not.
after adding this pixmap to my graphicsScene i don't see any image at all. the scrolling becomes very laggy and zooming in/out takes lots of time.

at the moment i'm quite happy with the simple QWidget viewport.
many thanks for usefull advice.