【问题标题】:how to get quality cropped bitmap when straighten applied for imageview in android如何在android中为imageview拉直时获得高质量的裁剪位图
【发布时间】:2016-05-09 21:38:32
【问题描述】:

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

我正在开发一个应用程序,它具有诸如具有纵横比的裁剪和具有旋转和拉直功能的裁剪等功能。为此,我正在使用this 库。具有裁剪、旋转和拉直功能,但我的问题是在调用裁剪功能以拉直图像后,结果质量不佳。我该如何克服这个问题?

这是我用于裁剪的代码:

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

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

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

感谢提前。

【问题讨论】:

    标签: android bitmap rotation crop


    【解决方案1】:

    尝试使用:

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

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

    否则只需将 Matrix 设置为 null。

    注意:Matrix rotate 方法是顺时针旋转正值,逆时针旋转负值。

    【讨论】:

    • 感谢回复。实际上“createScaledBitmap”没有六个参数。它只有四个参数,只是我尝试了四个参数,但质量不佳。
    • 我猜这就是我试图从记忆中做出回应的结果。只需使用 Bitmap.createBitmap。我会更新帖子以显示它。如果您仍然遇到问题,您可能需要使用更高分辨率的图片。有几个绘图程序可以做到这一点。我推荐 Krita。
    • 我也试过这样,但是当我将低分辨率图像调整为正常分辨率图像时,结果没有质量。
    • 我认为问题不在于位图的创建,而在于裁剪。你会检查吗?我也在看那个..
    • 位图参数后面的四个元素可用于裁剪图像,但听起来好像您的问题是起始图像的分辨率。它只能扩展这么多而不会开始看起来像素化。将 createBitmap 中的最后一个参数设置为 true 可以对此有所帮助,但听起来好像您需要一个好的图像创建程序。正如我所说,我推荐 Krita。它是免费的,但非常强大。许多人会看到可供选择的数量之多令人望而生畏,但如果您继续使用它,您会发现几乎没有什么是您无法使用的。
    猜你喜欢
    • 2021-01-26
    • 1970-01-01
    • 2013-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-06
    • 1970-01-01
    相关资源
    最近更新 更多