PictureSelector 3.0 如何裁剪? - LuckSiege/PictureSelector Wiki

更多请查阅 uCrop

setImageEngine(); 图片加载引擎
setCropOutputPathDir(); 自定义裁剪输出路径
setCropOutputFileName(); 自定义裁剪输出文件名
setMultipleCropAspectRatio(); 多图裁剪时每张对应的裁剪比例
isUseCustomLoaderBitmap(); uCrop使用自定义加载裁剪Bitmap
isForbidSkipMultipleCrop(); 多图裁剪时是否支持跳过
isUseCustomLoaderBitmap(); 是否使用自定义加载裁剪资源
isCropDragSmoothToCenter(); 图片是否跟随裁剪框居中
isForbidCropGifWebp(); 是否禁止裁剪gif和webp
isDarkStatusBarBlack();状态栏字体颜色是否黑色模式

onActivityResult Intent 支持的扩展字段 CustomIntentKey

以UCrop裁剪为例:

.setCropEngine(new CropEngine() {
        @Override
        public void onStartCrop(Fragment fragment, LocalMedia currentLocalMedia, ArrayList<LocalMedia> dataSource, int requestCode) {
        // 注意* 如果你实现自己的裁剪库,需要在Activity的.setResult(); 
        // Intent中需要给MediaStore.EXTRA_OUTPUT,塞入裁剪后的路径;如果有额外数据也可以通过CustomIntentKey.EXTRA_CUSTOM_EXTRA_DATA字段存入;
      
        // 1、构造可用的裁剪数据源
        String currentCropPath = currentLocalMedia.getAvailablePath();
        Uri inputUri;
        if (PictureMimeType.isContent(currentCropPath) || PictureMimeType.isHasHttp(currentCropPath)) {
            inputUri = Uri.parse(currentCropPath);
        } else {
            inputUri = Uri.fromFile(new File(currentCropPath));
        }
        String fileName = DateUtils.getCreateFileName("CROP_") + ".jpg";
        Uri destinationUri = Uri.fromFile(new File(getSandboxPath(), fileName));
        ArrayList<String> dataCropSource = new ArrayList<>();
        for (int i = 0; i < dataSource.size(); i++) {
            LocalMedia media = dataSource.get(i);
            dataCropSource.add(media.getAvailablePath());
        }
        UCrop uCrop = UCrop.of(inputUri, destinationUri, dataCropSource);
        uCrop.setImageEngine(new UCropImageEngine() {
            @Override
            public void loadImage(Context context, String url, ImageView imageView) {
                Glide.with(context).load(url).into(imageView);
            }
        });
        uCrop.withOptions(buildOptions());
        uCrop.start(fragment.getActivity(), fragment, requestCode);                      
        }
	});

setImageEngine(); 引擎

.setImageEngine(new UCropImageEngine() {
            @Override
            public void loadImage(Context context, String url, ImageView imageView) {
                if (!ImageLoaderUtils.assertValidRequest(context)) {
                    return;
                }
                Glide.with(context).load(url).into(imageView);
            }

            @Override
            public void loadImage(Context context, Uri url, int maxWidth, int maxHeight, OnCallbackListener<Bitmap> call) {
                if (!ImageLoaderUtils.assertValidRequest(context)) {
                    return;
                }
                Glide.with(context).asBitmap().override(maxWidth, maxHeight).load(url).into(new CustomTarget<Bitmap>() {
                    @Override
                    public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                        if (call != null) {
                            call.onCall(resource);
                        }
                    }

                    @Override
                    public void onLoadFailed(@Nullable Drawable errorDrawable) {
                        if (call != null) {
                            call.onCall(null);
                        }
                    }

                    @Override
                    public void onLoadCleared(@Nullable Drawable placeholder) {
                    }
                });
            }
        });