Solved mapToScene equivalent for a scaled QImage?
-
Hello,
I have a QImage that has a rectangle inside. After scaling it, I would like to know the coordinates of the scaled rectangle in the new, scaled QImage. Is there an easy way to achieve this?
Thanks a lot.
-
well, how do you
know the coordinates of the original rectangle ?Im not sure i 100% understand. you have an image, where inside
a rect is DRAWN ?
then you scale the whole image
and this drawn rect is also scaled with whole image?
and then you want to find the corrdinates?
inside the image? -
@mrjj exactly. There's a rectangle at position (x, y), whose size is (w, h) and I would like to know the new position (x', y') as well as its new size (w', h')
-
Ok:)
But do u even have the original coordinates of the rect?
before scale? -
@mrjj Yes. I think I'm going to go with
x' = scale_x*x
,y' = scale_y*y
,w' = scale_x*w
andh' = scale_y*h
but I'd rather Qt did it for me. This way I'd be sure there's no mistake. -
@Pippin
Well since its drawn inside othe image, not sure about any good Qt way :) -
QTransform matrix = QTransform().scale(0.5, 0.5); QImage scaledImg = img.transformed( matrix, Qt::SmoothTransformation ); QRect scaledRect = matrix.mapRect( originRect );
(untested)
-
@raven-worx
oh, i read the question as having a smaller drawn rect inside image. :) -
Thanks to both of you :-)