我需要获取画布内图像的边界以检测是否已被触摸,但如果我旋转画布 getbounds() 保持相同的值,如何在画布旋转后获得正确的值?
//CODE ON VIEW CLASS:
canvas.save();
canvas.rotate(rotation, Xpos, Ypos);
secHandImg.setBounds(left,top,right,bottom);
secHandImg.setAntiAlias(true);
secHandImg.draw(canvas);
circleHandImg.setBounds(left,top,right,bottom);
circleHandImg.setAntiAlias(true);
circleHandImg.draw(canvas);
canvas.restore();
//CODE ON FRAGMENT CLASS:
public boolean onTouch(View view, MotionEvent event) {
Rect imageBounds = MyClass.secHandImg.getBounds();
int action = event.getAction();
final int x = (int)event.getX();
final int y = (int)event.getY();
if(action == MotionEvent.ACTION_DOWN) {
if(x >= imageBounds.left && x < (imageBounds.left + imageBounds.width())
&& y >= imageBounds.top && y < (imageBounds.top + imageBounds.height())){
//THIS DON´T WORK IF CANVAS ROTATES
imageBoundsTouch = true;
}
}
这里有一张图片可以更好地解释我的问题: