Android 从位图裁剪梯形部分并创建矩形位图
我想使用我拥有的四个坐标点从位图中裁剪梯形部分。然后将此裁剪后的位图作为矩形图像作为结果位图 我想用Android java来做这件事,因为我不熟悉Android的C++原生开发或OpenCV。 图-Android 从位图裁剪梯形部分并创建矩形位图,android,Android,我想使用我拥有的四个坐标点从位图中裁剪梯形部分。然后将此裁剪后的位图作为矩形图像作为结果位图 我想用Android java来做这件事,因为我不熟悉Android的C++原生开发或OpenCV。 图- 拾取梯形的顶点作为源点,最后一个矩形的顶点作为目标点。使用findHomography查找变换,并使用warpPerspective。注意顶点顺序 // Set up a source polygon. // X and Y values are "flattened" int
拾取梯形的顶点作为源点,最后一个矩形的顶点作为目标点。使用findHomography查找变换,并使用warpPerspective。注意顶点顺序
// Set up a source polygon.
// X and Y values are "flattened" into the array.
float[] src = new float[8];
src[0] = x1; // from your diagram
src[1] = y1;
src[2] = x2;
src[3] = y2;
src[4] = x3;
src[5] = y3;
src[6] = x4;
src[7] = y4;
// set up a dest polygon which is just a rectangle
float[] dst = new float[8];
dst[0] = 0;
dst[1] = 0;
dst[2] = width;
dst[3] = 0;
dst[4] = width;
dst[5] = height;
dst[6] = 0;
dst[7] = height;
// create a matrix for transformation.
Matrix matrix = new Matrix();
// set the matrix to map the source values to the dest values.
boolean mapped = matrix.setPolyToPoly (src, 0, dst, 0, 4);
// check to make sure your mapping succeeded
// if your source polygon is a distorted rectangle, you should be okay
if (mapped) {
// create a new bitmap from the original bitmap using the matrix for transform
Bitmap imageOut = Bitmap.createBitmap(imageIn, 0, 0, width, height, matrix, true);
}