安卓得到位图矩形(左,上,右,下)在画布位图、画布、矩形

2023-09-07 08:52:22 作者:证明给你看

我绘制位图在一个画布,然后做一些尺度上,pretty的简单,只需使用canvas.scale(INT,INT,支点,支点),然后,缩放完成后,我需要得到相对于视口位图的坐标。有没有什么简便的方法来做到这一点没有通过自己计算的初始位置是又在哪里规模后,它去?

I am drawing a Bitmap over a Canvas and then doing some scaling on it, pretty simple, just using canvas.scale(int, int, pivot, pivot), and then, after the scaling is completed, I need to get the Bitmap's coordinates relative to the viewport. Is there any convenient way to do this without calculating by myself what the initial position is then where it went after the scale?

实际上,随着缩放的位图可以得到大于画布,所以我需要实际视图的夹大小和所述位图(即不可见的区域的大小和我想小于x低,Y(0, 0)。

Actually, the Bitmap with the scaling can get bigger than the Canvas, so I need actually the clip size of the view and the bitmap (the size of the area that is invisible and I suppose lower than x,y(0,0).

推荐答案

我想这样的:

canvas.scale(scaleX, scaleY, pivotX, pivotY);    

if (scaleX >= 1){       
  objectNewX = objectOldX + (objectOldX - pivotX)*(scaleX - 1);  
}else{      
  objectNewX = objectOldX - (objectOldX - pivotX)*(1 - scaleX);  
} 

相同的Y和另一角,这是把我的头顶部,还没有尝试过...

the same for Y and the other corner, this is off the top of my head, have not tried it...

 
精彩推荐
图片推荐