安卓得到位图矩形(左,上,右,下)在画布 [英] Android get Bitmap Rect (left, top, right, bottom) on a Canvas

查看:315
本文介绍了安卓得到位图矩形(左,上,右,下)在画布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我绘制位图在一个画布,然后做一些尺度上,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...

这篇关于安卓得到位图矩形(左,上,右,下)在画布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆