Discussion:
QPainter rotate bounding rect?
(too old to reply)
Jason H
2018-03-02 17:51:42 UTC
Permalink
Raw Message
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;
}
Murphy, Sean
2018-03-02 18:22:36 UTC
Permalink
Raw Message
I didn't check to see if it's built in to Qt or not, but here's the math you need to make it work yourself

http://iiif.io/api/annex/notes/rotation/

Sean


This message has been scanned for malware by Forcepoint. www.forcepoint.com
Giuseppe D'Angelo
2018-03-02 20:28:13 UTC
Permalink
Raw Message
Post by Jason H
How can I find the proper size that out should be, and where to place the image for drawImage within the new bounding box?
Use QTransform::mapRect() or a similar function.

HTH,
--
Giuseppe D'Angelo | ***@kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts
Loading...