我正在开发一款应用。
我需要压缩图像,就像Whatsapp在他们的应用程序中所做的那样。
我尝试过许多解决方案,例如:
Image compression like Whatsapp and other messengers on Android
我已经按照上面的所有解决方案,因为Whatsapp没有产生完美的结果。
压缩后的大小与Whatsapp不同。
他们的任何其他解决方案是否与Whatsapp完全相同的压缩算法。
任何帮助将不胜感激。
你可以尝试以下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是质量参数,如果要减小尺寸,降低质量值
使用this class compresses图像而不会失去其质量(差不多)。