Saving rotated QImage
-
Hi There,
I have a Problem saving rotated QImages. I load an Image, rotate it by some angle and want to save the result.
Unfortunately the results look very strange, either black or black & white patterns. (for 90° it works)Even when i rotate the image and cut out a rectangular part, saving this smaller part has the same problems.
I somehow could not find any related problems.
-
maybe i should post my code :)
@
QTransform trans;
trans.rotate(45);
QImage pic = m_currentImage.transformed(trans,Qt::SmoothTransformation);// n18 is a point in the original image, so i map it with trans and calculate borders of the rect used // later
QPoint tl = (trans.map(n18.toPoint()) - QPoint(75,150));
QPoint br = (trans.map(n18.toPoint()) + QPoint(75,150));QRect rec = QRect(tl,br);
// this would cut out the rectangle, it also shows in my program as a perfect rectangle
// pic = pic.copy(rec);QImageWriter w(QCoreApplication::applicationDirPath() + "/imagedat/blub.png","png");
w.write(pic);@And the output picture does not look any familiar with the original image. Just totally weird.
If i set the angle to 90° it outputs the right picture rotated by 90°. -
If anyone is interested in the Solution:
I now tried to apply the transformation to the pixmap and converted back to QImage and this works!!!
I still wonder why exactly this is the case.