【发布时间】:2020-02-15 19:07:22
【问题描述】:
我正在使用画布在另一个内部绘制两个矩形(这是一个交互式图像裁剪视图)
问题是蓝色矩形也可以缩放和旋转(我在位图上使用 Matrix() 来做到这一点):
我可以像这样在没有旋转的情况下计算边界:
if( ( centerX - offsetX ) > ( greenRectangleWidth / 2f ) )
// out of bounds
但是如果蓝色矩形旋转,我完全不知道如何计算蓝色矩形是否仍在绿色矩形内。我想我可以通过两种方式解决这个问题:
1. Read the pixel color of the edges of the blue square, if any of the edges will be outside the green square, the color will change. This seems like an unreliable way and I don't think I can even read 'pixel value' from canvas, then I would need to convert it to bitmap on each frame which will be very slow.
2. Calculate if any of the corners of the blue rectangle cross the edge of the green rectangle, but I'm not sure where to go from here.
任何提示请如何最有效地解决这个问题?谢谢!
【问题讨论】:
-
有必要用canvas画吗? drawable 是实现这个正方形的另一种选择
-
@Niceumang 很遗憾,是的,因为它是一个交互式“图像裁剪”视图
标签: android