-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[image_picker] add resize quality #855
Changes from all commits
3f49787
1682aa7
916d151
4efbe5a
4d39878
b3d78fc
782cdd8
21c24ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,7 @@ buildscript { | |
| } | ||
| } | ||
|
|
||
| allprojects { | ||
| rootProject.allprojects { | ||
| repositories { | ||
| google() | ||
| jcenter() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ buildscript { | |
| repositories { | ||
| google() | ||
| jcenter() | ||
| mavenLocal() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unnecessary change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't need this |
||
| } | ||
|
|
||
| dependencies { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,15 +26,16 @@ class ImageResizer { | |
| * | ||
| * <p>If no resizing is needed, returns the path for the original image. | ||
| */ | ||
| String resizeImageIfNeeded(String imagePath, Double maxWidth, Double maxHeight) { | ||
| String resizeImageIfNeeded( | ||
| String imagePath, Double maxWidth, Double maxHeight, Double resizeQuality) { | ||
| boolean shouldScale = maxWidth != null || maxHeight != null; | ||
|
|
||
| if (!shouldScale) { | ||
| return imagePath; | ||
| } | ||
|
|
||
| try { | ||
| File scaledImage = resizedImage(imagePath, maxWidth, maxHeight); | ||
| File scaledImage = resizedImage(imagePath, maxWidth, maxHeight, resizeQuality); | ||
| exifDataCopier.copyExif(imagePath, scaledImage.getPath()); | ||
|
|
||
| return scaledImage.getPath(); | ||
|
|
@@ -43,7 +44,8 @@ String resizeImageIfNeeded(String imagePath, Double maxWidth, Double maxHeight) | |
| } | ||
| } | ||
|
|
||
| private File resizedImage(String path, Double maxWidth, Double maxHeight) throws IOException { | ||
| private File resizedImage(String path, Double maxWidth, Double maxHeight, Double resizeQuality) | ||
| throws IOException { | ||
| Bitmap bmp = BitmapFactory.decodeFile(path); | ||
| double originalWidth = bmp.getWidth() * 1.0; | ||
| double originalHeight = bmp.getHeight() * 1.0; | ||
|
|
@@ -58,6 +60,8 @@ private File resizedImage(String path, Double maxWidth, Double maxHeight) throws | |
| boolean shouldDownscaleHeight = hasMaxHeight && maxHeight < originalHeight; | ||
| boolean shouldDownscale = shouldDownscaleWidth || shouldDownscaleHeight; | ||
|
|
||
| resizeQuality = resizeQuality != null ? resizeQuality : new Double(1.0); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| if (shouldDownscale) { | ||
| double downscaledWidth = (height / originalHeight) * originalWidth; | ||
| double downscaledHeight = (width / originalWidth) * originalHeight; | ||
|
|
@@ -85,7 +89,7 @@ private File resizedImage(String path, Double maxWidth, Double maxHeight) throws | |
|
|
||
| Bitmap scaledBmp = Bitmap.createScaledBitmap(bmp, width.intValue(), height.intValue(), false); | ||
| ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); | ||
| scaledBmp.compress(Bitmap.CompressFormat.JPEG, 100, outputStream); | ||
| scaledBmp.compress(Bitmap.CompressFormat.JPEG, (int) (resizeQuality * 100), outputStream); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| String[] pathParts = path.split("/"); | ||
| String imageName = pathParts[pathParts.length - 1]; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ buildscript { | |
| repositories { | ||
| google() | ||
| jcenter() | ||
| mavenLocal() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unnecessary change |
||
| } | ||
|
|
||
| dependencies { | ||
|
|
@@ -13,6 +14,7 @@ allprojects { | |
| repositories { | ||
| google() | ||
| jcenter() | ||
| mavenLocal() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unnecessary change |
||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ class ImagePicker { | |
| @required ImageSource source, | ||
| double maxWidth, | ||
| double maxHeight, | ||
| double resizeQuality, | ||
| }) async { | ||
| assert(source != null); | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check for value between 0.0 and 1.0 |
||
|
|
@@ -50,6 +51,7 @@ class ImagePicker { | |
| 'source': source.index, | ||
| 'maxWidth': maxWidth, | ||
| 'maxHeight': maxHeight, | ||
| 'resizeQuality': resizeQuality, | ||
| }, | ||
| ); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We prob don't need this.