Clever image zooming. What to write in PaintEvent?
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.
Re: Clever image zooming. What to write in PaintEvent?
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.
Re: Clever image zooming. What to write in PaintEvent?
Ok. I'm now looking at the QGraphicsScene/View.
I made a
Code:
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.
Re: Clever image zooming. What to write in PaintEvent?
And i got the same problem with unsmoothed image when i
Code:
myGraphicsScene
->addPixmap
( QPixmap::fromImage(image
) );
Re: Clever image zooming. What to write in PaintEvent?
try
Code:
graphicsView
->setRenderHint
(QPainter::SmoothPixmapTransform);
and/or
Code:
item->setTransformationMode(Qt::SmoothTransformation);
and/or
Re: Clever image zooming. What to write in PaintEvent?
many thanx, spud!
this solution works!
Code:
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!
Re: Clever image zooming. What to write in PaintEvent?
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).
Re: Clever image zooming. What to write in PaintEvent?
Quote:
Originally Posted by
spud
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.
Re: Clever image zooming. What to write in PaintEvent?
Quote:
Originally Posted by
wysota
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.
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.