我想旋转并将旋转的位图保存到特定的文件路径而不压缩它。在我使用下面的代码进行旋转,压缩并将其存储到特定文件之前。现在我想要压缩我的位图。请建议我旋转并将位图保存到指定路径。
public static void compressToStandard(String file) {
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inJustDecodeBounds = true;
BitmapFactory.decodeFile(file, bmOptions);
bmOptions.inJustDecodeBounds = false;
bmOptions.inSampleSize = getInSampleSize(bmOptions);
try {
Bitmap bitmap = BitmapFactory.decodeFile(file, bmOptions);
bitmap = ExifUtils.rotateBitmap(file, bitmap);
Log.i("ImageUtils", "compressed bitmap size:" + bitmap.getWidth() + "x" + bitmap.getHeight());
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, new FileOutputStream(file));
} catch (Exception e) {
e.printStackTrace();
}
}
当我打电话给这个方法时。我将把我的图像路径传递给这个方法。
答案 0 :(得分:1)
PNG无损,因此您可以使用Bitmap.CompressFormat.PNG
压缩
Hint to the compressor, 0-100. 0 meaning compress for
small size, 100 meaning compress for max quality. Some
formats, like PNG which is lossless, will ignore the
quality setting