保存的JPEG是旋转后从磁盘加载的JPEG的两倍

red*_*olf 2 android

在我的应用程序中,我使用ACTION_IMAGE_CAPTUREIntent来拍照.当相机返回时,将检查文件,如果旋转是纵向,则使用以下代码旋转位图并将其保存到磁盘:

BitmapFactory.Options options = new Options();
options.inPreferredConfig = Bitmap.Config.RGB_565;
Bitmap bmp = BitmapFactory.decodeFile(f.getAbsolutePath(), options);
if (bmp != null) {
    Matrix m = new Matrix();
    m.postRotate(90);
    Bitmap rotated = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), m,
                                        true);
    rotated = rotated.copy(Bitmap.Config.RGB_565, false); // added based on comment
    f.delete();
    FileOutputStream fos = new FileOutputStream(f);
    rotated.compress(Bitmap.CompressFormat.JPEG, 100, fos);
    fos.close();
}
Run Code Online (Sandbox Code Playgroud)

这应该工作,但文件大小是非旋转图片的两倍.我已经尝试将密度设置BitmapFactory.Options为0并将比例设置为false,但两者都没有达到预期的效果.我希望我转换的图像大小与从磁盘加载的图像大小相同.我的代码中是否存在阻止这种情况发生的事情?

Mus*_*sis 7

您的原始JPEG使用RGB565,每个像素使用2个字节.从此文件派生的内存中位图使用"普通"格式,每个像素4个字节; 当它保存为新的JPEG时,它以更密集的格式保存,因此是两倍大小(这与其旋转无关).