开发者

Get measured size and position of bitmap on canvas after 2D transformation

开发者 https://www.devze.com 2023-03-03 12:34 出处:网络
I have a bun开发者_如何学运维ch of bitmaps that I draw on a Canvas applied with 2D transformation (android.graphics.Camera and android.graphics.Matrix). How do I get the sizes/positions of the bitmaps

I have a bun开发者_如何学运维ch of bitmaps that I draw on a Canvas applied with 2D transformation (android.graphics.Camera and android.graphics.Matrix). How do I get the sizes/positions of the bitmaps on Canvas? The size would be the bounds of the bitmap as rendered on Canvas and the position would be the coordinates of the top/left corner of the bounds. All the bitmaps are regular rectangles without an alpha channel.


The matrix class has a mapRect function for this purpose:

mapRect(RectF dst, RectF src) Apply this matrix to the src rectangle, and write the transformed rectangle into dst.

Give the dimensions of the image as the source (and 0,0 for the x,y if you're using the whole image) and it will give you the transformed dimensions back as the dst rectangle.

0

精彩评论

暂无评论...
验证码 换一张
取 消