小编Pep*_*ruz的帖子

在某些情况下,在Android上将图像扭曲为四边形会失败

我正在使用matrix.setPolyToPoly函数将位图的选定区域(4个角)转换为矩形,通常它工作得很棒.但在下一个例子中:

4角选择图像

polyToPoly函数未通过透视变换:

转换图像不好

我画了两行进行测试,这些线标记了我想要四个选定点的位置.

我做错了什么?谢谢!

编辑:我已经使用canvas.drawBitmapMesh解决了问题,感谢pskink的建议!!

这是最终的代码

private float[] generateVertices(int widthBitmap, int heightBitmap) {
    float[] vertices=new float[(WIDTH_BLOCK+1)*(HEIGHT_BLOCK+1)*2];

    float widthBlock = (float)widthBitmap/WIDTH_BLOCK;
    float heightBlock = (float)heightBitmap/HEIGHT_BLOCK;

    for(int i=0;i<=HEIGHT_BLOCK;i++)
        for(int j=0;j<=WIDTH_BLOCK;j++) {
            vertices[i * ((HEIGHT_BLOCK+1)*2) + (j*2)] = j * widthBlock;
            vertices[i * ((HEIGHT_BLOCK+1)*2) + (j*2)+1] = i * heightBlock;
        }
    return vertices;
}

private Bitmap perspectiveTransformation(Bitmap bitmap, ArrayList<Point> bitmapPoints) {

    Bitmap correctedBitmap;
    int maxX = (int) Math.max(Math.abs(bitmapPoints.get(0).x - bitmapPoints.get(1).x), Math.abs(bitmapPoints.get(2).x - bitmapPoints.get(3).x));
    int maxY = (int) Math.max(Math.abs(bitmapPoints.get(0).y - bitmapPoints.get(3).y), …
Run Code Online (Sandbox Code Playgroud)

android matrix perspective android-bitmap

8
推荐指数
1
解决办法
538
查看次数

标签 统计

android ×1

android-bitmap ×1

matrix ×1

perspective ×1