安卓:相机裁剪意图在Lollipop及以上版本上显示提示消息"此图像不支持编辑"

3

如果要裁剪在Lollipop及以上版本中拍摄的Android手机图片,应该使用文件提供程序,以下是我的代码。

<provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="com.example.test.fileprovider"
            android:grantUriPermissions="true"
            android:exported="false"
            >
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/filepaths"
                />

        </provider>

<paths>
    <external-path name="myexternalimages" path="dcim/ProfileImage/"/>
</paths>





 final  Uri providedUri = FileProvider.getUriForFile(ProfileUpdateActivity.this,
                    "com.example.test.fileprovider", imageUpLoadFile);
            Intent cropIntent = new Intent("com.android.camera.action.CROP");



            //indicate image type and Uri
            cropIntent.setDataAndType(providedUri, "image/*");
            //set crop properties
            cropIntent.putExtra("crop", "true");
            //indicate aspect of desired crop
            cropIntent.putExtra("aspectX", 1);
            cropIntent.putExtra("aspectY", 1);
            //indicate output X and Y
            cropIntent.putExtra("outputX", 256);
            cropIntent.putExtra("outputY", 256);
            //retrieve data on return
            cropIntent.putExtra("return-data", true);

            // Exception will be thrown if read permission isn't granted
            cropIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

            startActivityForResult(cropIntent, PIC_CROP);

where imageUploadFile =/storage/emulated/0/dcim/ProfileImage/IMG_20160330_134823_1697877403.png (Example)

现在当它成功返回onActivityResult时,我会收到一个错误提示信息,内容为“无法编辑此图像”。


你解决了吗? - Vishal Puri
@VishalPuri 嗯,全部完成了。 - Sutirth
你是怎么解决它的? - Vishal Puri
@VishalPuri将图像缩小并编写了新的函数。 - Sutirth
1个回答

1

对我来说,将 EXTRA_OUTPUT 添加到意图中解决了问题。

cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, providedUri);  

但是请确保在Intent中添加写入Uri权限。
这样相机应用程序就可以将裁剪后的图像写入提供的Uri中。
cropIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);

功能正常,但在编辑图像后,无法保存,仍保留原始图像。 - Solanki Zeel

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接