Antialiasing for QPixmap scaled in a QGraphicsScene
-
Hi Jassie,
I had to implement it completely manually.
Simply create small resized versions of your image when loading it or on demand and load them into your graphicsview depending on the zoom value.You get the best results when your image has the actual size in which it is displayed in. (e.g. if you zoom out so your image will only be 512px wide, resize it to 512px before loading it into the interface)
-
Hi Jassie,
I had to implement it completely manually.
Simply create small resized versions of your image when loading it or on demand and load them into your graphicsview depending on the zoom value.You get the best results when your image has the actual size in which it is displayed in. (e.g. if you zoom out so your image will only be 512px wide, resize it to 512px before loading it into the interface)
-
As an example:
I load my original image with size 1024px. It is displayed in my graphicsview with the same size.
Now i zoom out 50%. But instead of scaling the graphicsview, simply resize the original image to 512px (with QT or openCV) and reload it into the graphicsview. -
As an example:
I load my original image with size 1024px. It is displayed in my graphicsview with the same size.
Now i zoom out 50%. But instead of scaling the graphicsview, simply resize the original image to 512px (with QT or openCV) and reload it into the graphicsview. -
When you want the best result there is no other option as drawing the image in exact the size shown on screen.(in Pixel)
To archive this you could subclass QGraphicsPixmapItem and override paint.
There you have to load the pixmap in the correct size (try to map your scene coordinates to pixels).
To load an Image in an scaled size you could for example use QImageReader :
http://doc.qt.io/qt-5/qimagereader.html#setScaledSize
Of course you have to cache the loaded Pixmap yourself.
When you reach paint event with the same size your code should use the cached pixmap. -
When you want the best result there is no other option as drawing the image in exact the size shown on screen.(in Pixel)
To archive this you could subclass QGraphicsPixmapItem and override paint.
There you have to load the pixmap in the correct size (try to map your scene coordinates to pixels).
To load an Image in an scaled size you could for example use QImageReader :
http://doc.qt.io/qt-5/qimagereader.html#setScaledSize
Of course you have to cache the loaded Pixmap yourself.
When you reach paint event with the same size your code should use the cached pixmap. -
Or simply calculate all possible images for all zoom steps at the start.
That means if your zoom values range from 10% to 100% with zoom step +10% simply calculate all 9 images at the start, cache them and load them depending on the zoom value.
QPixmap pixmap100, pixmap90, pixmap80, pixmap70 ... (etc)
you would have to limit the number of possible zoom values of course to avoid long loading times and huge amount of data.
-
Or simply calculate all possible images for all zoom steps at the start.
That means if your zoom values range from 10% to 100% with zoom step +10% simply calculate all 9 images at the start, cache them and load them depending on the zoom value.
QPixmap pixmap100, pixmap90, pixmap80, pixmap70 ... (etc)
you would have to limit the number of possible zoom values of course to avoid long loading times and huge amount of data.