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

感情迁移 提交于 2019-12-01 05:10:59

问题


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 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).


回答1:


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...



来源:https://stackoverflow.com/questions/6749723/android-get-bitmap-rect-left-top-right-bottom-on-a-canvas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!