Skip to content

Commit

Permalink
fix some OOM, do not upscale images
Browse files Browse the repository at this point in the history
  • Loading branch information
David Boho committed Jul 10, 2018
1 parent 9dcb7a0 commit f5b88d5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/android/CameraLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,6 @@ private Bitmap getScaledAndRotatedBitmap(String imageUrl, boolean unknownSources
// determine the correct aspect ratio
int[] widthHeight = calculateAspectRatio(rotatedWidth, rotatedHeight);


// Load in the smallest bitmap possible that is closest to the size we want
options.inJustDecodeBounds = false;
options.inSampleSize = calculateSampleSize(rotatedWidth, rotatedHeight, widthHeight[0], widthHeight[1]);
Expand Down Expand Up @@ -1122,8 +1121,10 @@ private Bitmap getScaledAndRotatedBitmap(String imageUrl, boolean unknownSources
* @return
*/
public int[] calculateAspectRatio(int origWidth, int origHeight) {
int newWidth = this.targetWidth;
int newHeight = this.targetHeight;
// fix some OOM
// do not upscale image
int newWidth = Math.min(this.targetWidth, origWidth);
int newHeight = Math.min(this.targetHeight, origHeight);

// If no new width or height were specified return the original bitmap
if (newWidth <= 0 && newHeight <= 0) {
Expand Down
8 changes: 4 additions & 4 deletions src/ios/UIImage+CropScaleOrientation.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ - (UIImage*)imageByScalingAndCroppingForSize:(CGSize)targetSize
CGSize imageSize = sourceImage.size;
CGFloat width = imageSize.width;
CGFloat height = imageSize.height;
CGFloat targetWidth = targetSize.width;
CGFloat targetHeight = targetSize.height;
CGFloat targetWidth = MIN(targetSize.width, width);
CGFloat targetHeight = MIN(targetSize.height, height);
CGFloat scaleFactor = 0.0;
CGFloat scaledWidth = targetWidth;
CGFloat scaledHeight = targetHeight;
Expand Down Expand Up @@ -136,8 +136,8 @@ - (UIImage*)imageByScalingNotCroppingForSize:(CGSize)targetSize
CGSize imageSize = sourceImage.size;
CGFloat width = imageSize.width;
CGFloat height = imageSize.height;
CGFloat targetWidth = targetSize.width;
CGFloat targetHeight = targetSize.height;
CGFloat targetWidth = MIN(targetSize.width, width);
CGFloat targetHeight = MIN(targetSize.height, height);
CGFloat scaleFactor = 0.0;
CGSize scaledSize = targetSize;

Expand Down

0 comments on commit f5b88d5

Please sign in to comment.