Skip to content

Commit f5b88d5

Browse files
committed
fix some OOM, do not upscale images
apache#238
1 parent 9dcb7a0 commit f5b88d5

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/android/CameraLauncher.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,6 @@ private Bitmap getScaledAndRotatedBitmap(String imageUrl, boolean unknownSources
10641064
// determine the correct aspect ratio
10651065
int[] widthHeight = calculateAspectRatio(rotatedWidth, rotatedHeight);
10661066

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

11281129
// If no new width or height were specified return the original bitmap
11291130
if (newWidth <= 0 && newHeight <= 0) {

src/ios/UIImage+CropScaleOrientation.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ - (UIImage*)imageByScalingAndCroppingForSize:(CGSize)targetSize
2828
CGSize imageSize = sourceImage.size;
2929
CGFloat width = imageSize.width;
3030
CGFloat height = imageSize.height;
31-
CGFloat targetWidth = targetSize.width;
32-
CGFloat targetHeight = targetSize.height;
31+
CGFloat targetWidth = MIN(targetSize.width, width);
32+
CGFloat targetHeight = MIN(targetSize.height, height);
3333
CGFloat scaleFactor = 0.0;
3434
CGFloat scaledWidth = targetWidth;
3535
CGFloat scaledHeight = targetHeight;
@@ -136,8 +136,8 @@ - (UIImage*)imageByScalingNotCroppingForSize:(CGSize)targetSize
136136
CGSize imageSize = sourceImage.size;
137137
CGFloat width = imageSize.width;
138138
CGFloat height = imageSize.height;
139-
CGFloat targetWidth = targetSize.width;
140-
CGFloat targetHeight = targetSize.height;
139+
CGFloat targetWidth = MIN(targetSize.width, width);
140+
CGFloat targetHeight = MIN(targetSize.height, height);
141141
CGFloat scaleFactor = 0.0;
142142
CGSize scaledSize = targetSize;
143143

0 commit comments

Comments
 (0)