c++qttransformationimage-qualityqgraphicspixmapitem

Scaled and transform Qgraphicspixmapitem


I have a problem while scaling and transforming QGraphicsPixmapItem. I have created graphics editor in which I am using QGraphicsItem of initial size 100,100 and after that I am resizing and rotating it by setTransform() method.

After that I am storing this transform and using these for my another application called player in which I am using those transform and showing images and videos on it, I am using QgraphicsPixmapItem to show images now if I set scaled and setTransform methods to image its clarity gets spoiled.

Is it possible to keep clarity as it is even if I scaled and transform it.The image I am using is of 2560x1440 pixels. Any help will be appreciated.

The code is :

QGraphicsPixmapItem *pixitem = new QGraphicsPixmapItem;
pixitem->setFlags(QGraphicsItem::ItemIsMovable);
pixitem->setPos(50,50);
QTransform trans;
trans.setMatrix(4.20399,2.9286,0,-3.86601,0.761397,0,33.1015,-134.5,1);
pixitem->setPixmap(QPixmap("abc.jpg").scaled(100,100));
pixitem->setTransform(trans);
pixitem->setShapeMode(QGraphicsPixmapItem::MaskShape);
scene->addItem(pixitem);

Solution

  • You can use setTransformationMode function to set the pixmap item's transformation mode. The default value is Qt::FastTransformation. You should set the transform mode to Qt::SmoothTransformation to enable bilinear filtering which results in a better quality when scaled :

    pixitem->setTransformationMode(Qt::SmoothTransformation);