Android JPEG到位图到JPEG

Android JPEG到位图到JPEG,android,bitmap,size,jpeg,reduce,Android,Bitmap,Size,Jpeg,Reduce,我保存的图像大小有问题。假设我有一个JPEG,它是1028 x 960,我会将文件读入位图并进行一些编辑,然后再次将其保存为JPEG。图像将为514 x 480。我能做些什么来保持尺寸不变吗 这是我读取文件时的代码: private void choosePhoto() { generalIntent = new Intent(Intent.ACTION_GET_CONTENT); generalIntent.setType("image/*"); startActivi

我保存的图像大小有问题。假设我有一个JPEG,它是1028 x 960,我会将文件读入位图并进行一些编辑,然后再次将其保存为JPEG。图像将为514 x 480。我能做些什么来保持尺寸不变吗

这是我读取文件时的代码:

private void choosePhoto() {
    generalIntent = new Intent(Intent.ACTION_GET_CONTENT);
    generalIntent.setType("image/*");
    startActivityForResult(generalIntent, CHOOSE_PHOTO);
}
还有这个

if (requestCode == CHOOSE_PHOTO) {
    cleanUpImageView();
    tempImageUri[1] = data.getData();
    editPhotoImg.setImageURI(tempImageUri[1]);
}
这是保存文件的代码:

private void savePhoto() {
    if (editPhotoImg.getDrawable() == null) {
        Toast.makeText(EditPhoto.this, "No Photo Edited", Toast.LENGTH_SHORT).show();
    } else {
        try {
            String filePath = getOutputMediaFile(RESULT).getPath();
            editPhotoImg.setDrawingCacheEnabled(true);
            Bitmap b = editPhotoImg.getDrawingCache(true);

            b.compress(CompressFormat.JPEG, 100, new FileOutputStream(filePath));
            Toast.makeText(EditPhoto.this, "Image saved to: " + filePath,
                    Toast.LENGTH_SHORT).show();
        } catch (Exception e) {
            Toast.makeText(EditPhoto.this, "Invalid File Path", Toast.LENGTH_SHORT).show();
        }
    }
}

图像质量也下降了,但我想这可能是没办法的。但我真心希望,至少规模不会缩小。提前谢谢你的帮助。我很感激

您从哪里获得图片?gallery?您是否在任何地方使用参数“inSampleSize=2”?因为你的身高和宽度都减半了。纳约索,是的,我正在画廊里拍照片。如果我从其他地方得到它会有什么不同吗?因为我允许他们从照片上的任何地方选择图片。Royston,我没有在任何地方指定inSampleSize。但是默认值是=2吗?为此,我不确定,但设置insamplesize会解决我的问题吗?:)PNG格式可能最适合无损压缩