我有一个图像和一组四个点(描述四边形Q).我想转换这个图像,使其适合四边形Q.Photoshop称这种转换为"扭曲".但是根据这个四边形的来源(图像在空间中移动的视角),它实际上是尺度,旋转和透视矩阵的组合.
我想知道使用CATransform3D 4x4矩阵是否可行.你有任何关于如何做到这一点的提示吗?我试图取四个点并构建16个方程式(A'= A xu),但它不起作用:我不确定我应该使用什么作为z,z',w和w'系数......
下图显示了我想要做的事情:

以下是一些要点的例子:
276.523, 236.438, 517.656, 208.945, 275.984, 331.285, 502.23, 292.344
261.441, 235.059, 515.09, 211.5, 263.555, 327.066, 500.734, 295
229.031, 161.277, 427.125, 192.562, 229.16, 226, 416.48, 256
Run Code Online (Sandbox Code Playgroud) 我正在使用matrix.setPolyToPoly函数将位图的选定区域(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)