[Interest] QPainter rotate bounding rect?

Jason H jhihn at gmx.com
Fri Mar 2 18:51:42 CET 2018


When rotating an image about its center (code below) the corers get cut off. It needs to just be a little wider and a little taller. Is there a calculation already in Qt?
How can I find the proper size that out should be, and where to place the image for drawImage within the new bounding box?

QImage rotate(const QImage &in, qreal degrees) {
	QImage out = QImage(in.size(), in.format());

	QPainter painter;
	painter.begin(&out);
	painter.translate(QPoint(out.width()/2, out.height()/2));
	painter.rotate(degrees);
	painter.translate(QPoint(-out.width()/2, -out.height()/2));
	painter.drawImage(0,0, in);
	painter.end();
	return out;
}



More information about the Interest mailing list