我正在做一个需要实施图像矫正的项目。我有一个想法来做这件事。我将 SeekBar 上的图像旋转为 -10 到 +10 度。当我旋转时,它是由白色背景可见的。因此,我们还需要实现缩放功能,使其看起来像图像拉直,如下所示。请根据您的建议提出建议。
示例代码
float a = (float) Math.atan(bmpHeight/bmpWidth);
// the length from the center to the corner of the green
float len1 = (float) ((bmpWidth/2)/Math.cos(a-Math.abs(curRotate)));
// the length from the center to the corner of the black (^ = power)
float len2 = (float) Math.sqrt((bmpWidth/2)^2 + (bmpHeight/2)^2);
// compute the scaling factor
curScale = len2 / len1;
Matrix matrix = new Matrix();
matrix.postScale(curScale, curScale);
Bitmap resizedBitmap = Bitmap.createBitmap(bitmaprotate, 0, 0, bmpWidth, bmpHeight, matrix, true);
mainImage.setImageBitmap(resizedBitmap);