我是android新手。我想要精确地将位图的大小减小到100kb。我从SD卡上获取一张图片,将其压缩并以不同的名称再次保存到SD卡中,然后保存到不同的目录中。压缩工作正常(3 MB像图像被压缩到100 kb左右)。我试图将1MB图像压缩到100kb,但是我得到的图像大小是20kb。但我需要1MB(或2MB(或)3MB(或)4MB(或)5MB .....)图像也可以调整大小为100kb。并且我的代码是,,如何在android中将多个图像大小压缩为特定大小(100kb)?
private Bitmap getResizedBitmap(Bitmap bm,int maxSize) int width = bm.getWidth(); int height = bm.getHeight();
float bitmapRatio = (float)width/(float) height;
if (bitmapRatio > 0) {
width = maxSize;
height = (int) (width/bitmapRatio);
} else {
height = maxSize;
width = (int) (height * bitmapRatio);
}
return Bitmap.createScaledBitmap(bm, width, height, true);
}
+0
或者您可以使用矩阵,如果你想减少分辨率 –
+0
上述逻辑将重新调整图像宽度和高度或像素的大小,但我不确定它可以减小图像的桌面大小。 –
+0
你可以请我张贴代码缩小图像大小@HariRam –