If I have a canvas, on which I draw a Bitmap like this:
canvas.drawBitmap(bmLargeImage, srcRect, destRect, paint);
and I scale the bitmap:
canvas.scale(1.5f, 1.5f, 450, 250);
I want to get the position of the Bitmap after the scale. If the position before scale was (0, 0), after scale there is a offset and I need that offset.. how can I get it?
Thanks and sorry for the simple question, newbie here...
Ok lets try to work out the best formula for this
The same for objectNewY. The new width and height of the bitmap would of course be the multiple of the old size and scale.
If you'd like know the corners of your screen relative to your original canvas, you can use
canvas.getClipBounds()
. This returns aRect
with edge coordinates relative to your original canvas. For instance, if you start off with a canvas size of 320 x 480 and calland then
you will have a
Rect
(call thisrect
) whereI believe the cleanest Solution would be to use the underlying transformation Matrix of the Canvas you are manipulating.
In Android there is the
canvas.getMatrix(Matrix cmt)
method available which will yield it. The transformation matrix will transform any point in world space you throw at into screen coordinates. Just use thematrix.mapPoints(float[] points)
and you will be fine.FYI, you can easily do it the other way around too. If you want to know what screen coordinate maps to which point in world space, e.g. for tapping; the inverse matrix can be used for that. It can be obtained via the
matrix.invert(Matrix out)
method. Use itsmapPoints()
for the coordinate mapping then.Here are the official docs: mapPoints(), invert(), getMatrix()