如何压缩图像与Whatsapp相同

问题描述 投票:3回答:2

我正在开发一款应用。

我需要压缩图像,就像Whatsapp在他们的应用程序中所做的那样。

我尝试过许多解决方案,例如:

Image compression like Whatsapp and other messengers on Android

我已经按照上面的所有解决方案,因为Whatsapp没有产生完美的结果。

压缩后的大小与Whatsapp不同。

他们的任何其他解决方案是否与Whatsapp完全相同的压缩算法。

任何帮助将不胜感激。

android image-compression
2个回答
0
投票

你可以尝试以下first 之一

要么

FileOutputStream out = null;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bmp = BitmapFactory.decodeFile(photoPath, options);
try {
out = new FileOutputStream(filename);
bmp.compress(CompressFormat.JPEG, 70, out);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
    if (out != null) {
        out.close();
    }
} catch (IOException e) {
    e.printStackTrace();
}
}

70是质量参数,如果要减小尺寸,降低质量值


-3
投票

使用this class compresses图像而不会失去其质量(差不多)。

© www.soinside.com 2019 - 2024. All rights reserved.