Skip to content

PictureSelector 3.0 如何编辑图片?

Luck edited this page Jan 15, 2022 · 2 revisions

以UCrop裁剪编辑为例:

onActivityResult Intent 支持的扩展字段 CustomIntentKey

.setEditMediaInterceptListener(new OnMediaEditInterceptListener() {
       @Override
       public void onStartMediaEdit(Fragment fragment, LocalMedia currentLocalMedia, int requestCode) {
       // 注意* 如果你实现自己的编辑库,需要在Activity的.setResult(); Intent中需要给MediaStore.EXTRA_OUTPUT保存编辑后的路径;
       // 如果有额外数据也可以通过CustomIntentKey.EXTRA_CUSTOM_EXTRA_DATA字段存入;
       
       // 1、构造编辑的数据源
        String currentEditPath = currentLocalMedia.getAvailablePath();
        Uri inputUri = PictureMimeType.isContent(currentEditPath)
                ? Uri.parse(currentEditPath) : Uri.fromFile(new File(currentEditPath));
        Uri destinationUri = Uri.fromFile(
                new File(getSandboxPath(), DateUtils.getCreateFileName("CROP_") + ".jpeg"));
        UCrop uCrop = UCrop.of(inputUri, destinationUri);
        UCrop.Options options = buildOptions();
        options.setHideBottomControls(false);
        uCrop.withOptions(options);
        uCrop.startEdit(fragment.getActivity(), fragment, requestCode);                       
       }
   });