开发者

Android get Bitmap Rect (left, top, right, bottom) on a Canvas

开发者 https://www.devze.com 2023-03-21 03:58 出处:网络
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 Bitma

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?

Actually, the Bitmap with the scaling can get bigger than the Canvas, so I need a开发者_JAVA技巧ctually 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).


I am thinking this:

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

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

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

0

精彩评论

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