-
Notifications
You must be signed in to change notification settings - Fork 3k
PictureSelector 3.0 如何裁剪?
Luck edited this page Apr 5, 2022
·
11 revisions
更多请查阅 uCrop
setImageEngine(); 图片加载引擎
setCropOutputPathDir(); 自定义裁剪输出路径
setCropOutputFileName(); 自定义裁剪输出文件名
setMultipleCropAspectRatio(); 多图裁剪时每张对应的裁剪比例
setSkipCropMimeType(); 跳过裁剪的资源类型
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字段存入;
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) {
}
});
}
});