在2D转换后获得在画布上测量的位图大小和位置

mob*_*ofu 5 android canvas bitmap

我在Canvas上绘制了一堆位图,应用了2D变换(android.graphics.Camera和android.graphics.Matrix).如何在Canvas上获取位图的大小/位置?大小将是在Canvas上渲染的位图的边界,位置将是边界的上/左角的坐标.所有位图都是没有alpha通道的常规矩形.

Sim*_*ris 4

矩阵类有一个mapRect用于此目的的函数:

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

将图像的尺寸作为源(如果您使用整个图像,则将 0,0 表示 x,y),它将为您提供转换后的尺寸作为 dst 矩形。