繁体   English   中英

如何在Android中将图像拉直应用到图像时获得高质量的裁剪位图

[英]how to get quality cropped bitmap when straighten applied for imageview in android

我认为它应该是重复的,但对于这个问题我没有任何解决方案。 我的问题是:

我正在开发一个应用程序,该应用程序具有诸如具有纵横比的裁切和具有旋转和拉直的裁切之类的功能。 为此,我正在使用库。 具有裁切,旋转和拉直功能,但工作正常,但是我的问题是在调用裁切功能以拉直图像后导致质量不佳。 我该如何克服这个问题?

这是我用于裁剪的代码:

private Bitmap getCurrentDisplayedImage() {
Bitmap result = Bitmap.createBitmap(mImageView.getWidth(), mImageView.getHeight(), Bitmap.Config.RGB_8888);
Canvas c = new Canvas(result);
mImageView.draw(c);
return result;}

// Get the scale factor between the actual Bitmap dimensions and the
// displayed dimensions for width.
float actualImageWidth = mCurrentDisplayedBitmap.getWidth();
float displayedImageWidth = displayedImageRect.width();
float scaleFactorWidth = actualImageWidth / displayedImageWidth;

// Get the scale factor between the actual Bitmap dimensions and the
// displayed dimensions for height.
float actualImageHeight = mCurrentDisplayedBitmap.getHeight();
float displayedImageHeight = displayedImageRect.height();
float scaleFactorHeight = actualImageHeight / displayedImageHeight;

// Get crop window position relative to the displayed image.
float cropWindowX = Edge.LEFT.getCoordinate() - displayedImageRect.left;
float cropWindowY = Edge.TOP.getCoordinate() - displayedImageRect.top;
float cropWindowWidth = Edge.getWidth();
float cropWindowHeight = Edge.getHeight();

// Scale the crop window position to the actual size of the Bitmap.
float actualCropX = cropWindowX * scaleFactorWidth;
float actualCropY = cropWindowY * scaleFactorHeight;
float actualCropWidth = cropWindowWidth * scaleFactorWidth;
float actualCropHeight = cropWindowHeight * scaleFactorHeight;

// Crop the subset from the original Bitmap.
Bitmap croppedBitmap = Bitmap.createBitmap(mCurrentDisplayedBitmap, (int) actualCropX, (int) actualCropY, (int) actualCropWidth, (int) actualCropHeight);
return croppedBitmap;}

我用谷歌搜索,尝试了很多方法,但是没有找到更好的解决方案。

如果有人有想法请帮助我。

感谢Adavance。

尝试使用:

Bitmap.createBitmap(Bitmap bitmap, int xStart, int yStart, int xSize, int ySize, Matrix matrix, boolean render)
并将render设置为true。 您还可以选择应用一个矩阵,该矩阵可以使用这种方法来处理旋转和调整大小,如下所示:

Matrix matrix = new Matrix();
matrix.postScale(float xScale, float yScale);
matrix.postRotate(int degrees);

否则,只需将Matrix设置为null。

注意:“矩阵旋转”方法以正值顺时针旋转,而负值则逆时针旋转。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM