图像处理:文件路径+ uri + exif数据(旋转)问题

时间:2016-03-24 18:43:19

标签: android image-processing android-intent android-camera-intent android-crop

我已经挣扎了好几天来创建一个从相机中拾取图像并将其有效地裁剪成方形的活动(不将图像加载到内存中)。

拍摄照片没什么大不了的:

Intent mediaPickingIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mediaPickingIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);

startActivityForResult(mediaPickingIntent, REQUEST_CODE_GENERIC);

然后,我尝试为每个设备使用OOTB裁剪功能,如:

String cropDestinationPath = getTemporaryImagePath();
Uri destination = Uri.fromFile(new File(cropDestinationPath));

Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.setDataAndType(source, "image/*");
cropIntent.putExtra("crop", "true");
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
cropIntent.putExtra("outputX", SQUARE_IMAGE_SIZE);
cropIntent.putExtra("outputY", SQUARE_IMAGE_SIZE);
cropIntent.putExtra("return-data", false);
cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, destination);

startActivityForResult(cropIntent, REQUEST_CODE_IMAGE_CROP);

现在,使用IMAGE_CAPTURE的输出路径,我能够检索表示图像旋转的exif数据(即:270度),但意图似乎并不关心exif数据。

我将生成的路径转换为uri,如:

    private Uri convertPathToContentUri(String imagePath) throws Exception {
            String imageName = null;
            String imageDescription = null;
            String uriString = MediaStore.Images.Media.insertImage(getContentResolver(), imagePath, imageName, imageDescription);
            return Uri.parse(uriString);
    }

BTW:我在三星设备上对此进行了测试,Nexus上的相同代码运行正常。

0 个答案:

没有答案