gpt4 book ai didi

android - 从位图中裁剪梯形部分并创建矩形结果位图

转载 作者:太空狗 更新时间:2023-10-29 13:11:31 28 4
gpt4 key购买 nike

我想使用我拥有的四个坐标点从位图中裁剪梯形部分。然后将这个裁剪后的位图作为矩形图像作为生成的位图。

我想用 Android JAVA 来做这件事,因为我不熟悉 C++ 原生开发或 openCV for android。

图- figure represents problem statement

最佳答案

    // 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);
}

关于android - 从位图中裁剪梯形部分并创建矩形结果位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40093300/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com