从梯形裁剪创建矩形位图

编程入门 行业动态 更新时间:2024-10-26 11:18:39
本文介绍了从梯形裁剪创建矩形位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想将点A,B,C,D表示的图像的梯形部分转换为矩形位图.

I would like to convert the trapezoid section of the image denoted by points A,B,C,D to a rectangle bitmap.

我能够使用户标记图像中的4个点,但是我不确定如何将梯形转换为矩形.

I am able to make the user mark the 4 points in the image, but I am not sure as to how can I convert the trapezoid to rectangle.

感谢社区的任何投入.

推荐答案

实现已完成.也感谢@IcedLance供参考.这是供将来参考和供社区使用.整个实现已完成.

The implementation has been done. Thanks for @IcedLance too for the reference. This is for future reference and for the community. The entire implementation has been done.

private Bitmap trapezoidToRectangleTransform() { float[] src = new float[8]; Point point = mAnchorPoints.get(0); src[0] = point.x; src[1] = point.y; point = mAnchorPoints.get(1); src[2] = point.x; src[3] = point.y; point = mAnchorPoints.get(3); src[4] = point.x; src[5] = point.y; point = mAnchorPoints.get(2); src[6] = point.x; src[7] = point.y; // set up a dest polygon which is just a rectangle float[] dst = new float[8]; dst[0] = 0; dst[1] = 0; dst[2] = mOriginalBitmap.getWidth(); dst[3] = 0; dst[4] = mOriginalBitmap.getWidth(); dst[5] = mOriginalBitmap.getHeight(); dst[6] = 0; dst[7] = mOriginalBitmap.getHeight(); // 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); float[] mappedTL = new float[] { 0, 0 }; matrix.mapPoints(mappedTL); int maptlx = Math.round(mappedTL[0]); int maptly = Math.round(mappedTL[1]); float[] mappedTR = new float[] { mOriginalBitmap.getWidth(), 0 }; matrix.mapPoints(mappedTR); int maptry = Math.round(mappedTR[1]); float[] mappedLL = new float[] { 0, mOriginalBitmap.getHeight() }; matrix.mapPoints(mappedLL); int mapllx = Math.round(mappedLL[0]); int shiftX = Math.max(-maptlx, -mapllx); int shiftY = Math.max(-maptry, -maptly); Bitmap croppedAndCorrected = null; if (mapped) { Bitmap imageOut = Bitmap.createBitmap(mOriginalBitmap, 0, 0, mOriginalBitmap.getWidth(), mOriginalBitmap.getHeight(), matrix, true); croppedAndCorrected = Bitmap.createBitmap(imageOut, shiftX, shiftY, mOriginalBitmap.getWidth(), mOriginalBitmap.getHeight(), null, true); imageOut.recycle(); mOriginalBitmap.recycle(); System.gc(); } return croppedAndCorrected; }

这里是链接:github/wwdablu/ExtImageView/blob/master/extimageview/src/main/java/com/wwdablu/soumya/extimageview/trapez/OriginalBitmapCropper.java

更多推荐

从梯形裁剪创建矩形位图

本文发布于:2023-08-02 03:45:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1274349.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:梯形   位图   矩形

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!