PDA

View Full Version : QPixmap being clipped after rotation



stereoMatching
25th November 2012, 20:33
QImage img("lena.jpg");

rotate_image_implace(img, angle); //rotate the img with angle degrees(90, 180, 270 and so on)

graph_scene_ = new QGraphicsScene(this);
graph_scene_->addItem(graph_pixmap_ = new QGraphicsPixmapItem);
graph_view_ = new QGraphicsView(graph_scene_, this);

graph_pixmap_->setPixmap(QPixmap::fromImage(img));
graph_scene_->setSceneRect(img.rect());


type of graph_pixmap_ is QGraphicsPixmapItem

type of graph_scene_ is QGraphicsScene

type of graph_view_ is QGraphicsView

This may clip the image if their height and width are different, how could I rotate the image without clipping it?

Because the program need to save the image after rotating and mirror(vertical and horizontal), rotation of QGraphicsPixmapItem is not adopted.

ChrisW67
25th November 2012, 21:38
You cannot rotate an x by y rectangular image without scaling and put it back into the same x by y space except in the limited case of a 180 degree rotation about the image centre. Assuming (because you have not shown us the code that you use to do this rotation) you are rotating about the centre of the x by y image then the rotated image will always fit in a square image sqrt(x*x + y*y) pixels on a side. Alternatively you can compute the minimal size of image you need to place the result in with simple trigonometry.