繁体   English   中英

如何降低bitmap的分辨率

[英]How to reduce resolution of bitmap

我有一些图像为 bitmap,

我想降低图像的分辨率,以便更容易使用(用于计算所有像素)。

  • 我想为不同尺寸的图像做这件事。
  • 我希望大小保持不变(当我在 imageView 中显示它时)

如何降低分辨率并创建一个新的bitmap来使用?

使用@blackapps 评论和使用@Padma Kumar 的答案解决了这个问题如何将图像(位图)调整为给定大小?

Bitmap scaledBitmap = scaleDown(realImage, MAX_IMAGE_SIZE, true);

public static Bitmap scaleDown(Bitmap realImage, float maxImageSize,
        boolean filter) {
    float ratio = Math.min(
            (float) maxImageSize / realImage.getWidth(),
            (float) maxImageSize / realImage.getHeight());
    int width = Math.round((float) ratio * realImage.getWidth());
    int height = Math.round((float) ratio * realImage.getHeight());

    Bitmap newBitmap = Bitmap.createScaledBitmap(realImage, width,
            height, filter);
    return newBitmap;
}

现在它起作用了!

暂无
暂无

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

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