Skip to content

Commit

Permalink
add option to set the max bitmap generated size. Default to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
mde-pach committed Mar 12, 2020
1 parent 61cb7fb commit 85930d5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ This project aims to provide an ultimate and flexible image cropping experience.

* **compressQuality**: the value [0 - 100] to control the quality of image compression.

* **maxBitmapSize**: the maximum size of the Bitmap object generated after cropping.

* **androidUiSettings**: controls UI customization on Android. See [Android customization](#android-1).

* **iosUiSettings**: controls UI customization on iOS. See [iOS customization](#ios-1).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public void startCrop(MethodCall call, MethodChannel.Result result) {
String cropStyle = call.argument("crop_style");
String compressFormat = call.argument("compress_format");
Integer compressQuality = call.argument("compress_quality");
Integer maxBitmapSize = call.argument("max_bitmap_size");
ArrayList<String> aspectRatioPresets = call.argument("aspect_ratio_presets");
String initAspectRatio = call.argument("android.init_aspect_ratio");
Integer maxBitmapSize = call.argument("android.max_bitmap_size");
Expand All @@ -53,6 +54,7 @@ public void startCrop(MethodCall call, MethodChannel.Result result) {
UCrop.Options options = new UCrop.Options();
options.setCompressionFormat("png".equals(compressFormat) ? Bitmap.CompressFormat.PNG : Bitmap.CompressFormat.JPEG);
options.setCompressionQuality(compressQuality != null ? compressQuality : 90);
options.setMaxBitmapSize(maxBitmapSize != null ? maxBitmapSize : 0);

// UI customization settings
if ("circle".equals(cropStyle)) {
Expand Down
5 changes: 5 additions & 0 deletions lib/src/cropper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class ImageCropper {
///
/// * compressQuality: the value [0 - 100] to control the quality of image compression
///
/// * maxBitmapSize: the maximum size of the Bitmap object generated after cropping
///
/// * androidUiSettings: controls UI customization on Android. See [AndroidUiSettings].
///
/// * iosUiSettings: controls UI customization on iOS. See [IOSUiSettings].
Expand Down Expand Up @@ -75,6 +77,7 @@ class ImageCropper {
CropStyle cropStyle = CropStyle.rectangle,
ImageCompressFormat compressFormat = ImageCompressFormat.jpg,
int compressQuality = 90,
int maxBitmapSize = 0,
AndroidUiSettings androidUiSettings,
IOSUiSettings iosUiSettings,
}) async {
Expand All @@ -83,6 +86,7 @@ class ImageCropper {
assert(maxWidth == null || maxWidth > 0);
assert(maxHeight == null || maxHeight > 0);
assert(compressQuality >= 0 && compressQuality <= 100);
assert(maxBitmapSize >= 0);

final arguments = <String, dynamic>{
'source_path': sourcePath,
Expand All @@ -95,6 +99,7 @@ class ImageCropper {
'crop_style': cropStyleName(cropStyle),
'compress_format': compressFormatName(compressFormat),
'compress_quality': compressQuality,
'max_bitmap_size': maxBitmapSize,
}
..addAll(androidUiSettings?.toMap() ?? {})
..addAll(iosUiSettings?.toMap() ?? {});
Expand Down

0 comments on commit 85930d5

Please sign in to comment.