Ash*_*hok 5 android bitmap matrix
我正在开发一个包含裁剪功能的应用程序,在这种情况下我在下面的场景中被阻止。
场景:
如果我们更改裁剪叠加,当我们对图像应用拉直时裁剪叠加不会循环整个图像,比例也不起作用。
我从谷歌得到了代码,但它与矩阵有关,我尝试使用矩阵,但在这里我需要找到矩阵的坐标(边)来移动叠加层。
如何找到它?如果有人有任何想法,请帮助我...
我添加了图像来解释问题
提前致谢..
我正在使用下面的代码,但我没有得到矩阵的确切坐标
RectF r = new RectF();
mymatrix.mapRect(r);
Rect rect =
new Rect((int)r.left,int)r.top,int)r.right+width,int)r.bottom+height);
Run Code Online (Sandbox Code Playgroud)
mapRect
如果您在矩阵上应用旋转,则不应使用。我的建议是找出代表每个矩形边缘(图像本身)的 4 个初始点并使用mapPoints
。
假设您有一个 200 像素宽和 200 像素高的图像,其左上角位于原点 (0,0)。
如果您将此图像从其中心 (100,100) 旋转 45 度,然后将其从其中心缩放 200%,我们将有以下场景:
//original image coords
float[] points = {
0f, 0f, //left, top
200f, 0f, //right, top
200f, 200f, //right, bottom
0f, 200f//left, bottom
};
Matrix matrix = new Matrix();
//rotate 45 degrees from image center
matrix.postRotate(45f, 100f, 100f);
//scale 200% from center
matrix.postScale(2f, 2f, 100f, 100f);
//get the new edges coords
matrix.mapPoints(points);
Run Code Online (Sandbox Code Playgroud)
调用matrix.mapPoints(points)
点数组后将有更新的坐标。这意味着points[0], points[1]
将有新的左上角图像坐标等等。
偶数索引表示横坐标,奇数索引表示points
阵列上的纵坐标。
归档时间: |
|
查看次数: |
1913 次 |
最近记录: |