如何在不压缩的情况下将旋转位图写入特定文件android

How to write rotated bitmap into specific file without compress android

我想旋转并将旋转后的位图保存到特定文件路径而不压缩它。在我使用下面的代码进行旋转、压缩并将其存储到特定文件之前。现在我不想压缩我的位图。请给我一个旋转位图并将其保存到指定路径的想法。

  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();
    }
}

当我调用这个方法时。我会将我的图像路径传递给此方法。

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