From 6f4fef8479d690b9037baa05ab4269f9279e1d80 Mon Sep 17 00:00:00 2001 From: Kevin Woram Date: Wed, 2 Oct 2013 16:58:41 -0500 Subject: [PATCH] CB-5599 Android: Catch and ignore OutOfMemoryError in getRotatedBitmap() getRotatedBitmap() can run out of memory if the image is very large: http://simonmacdonald.blogspot.ca/2012/07/change-to-camera-code-in-phonegap-190.html If this happens, simply do not rotate the image and return it unmodified. If you do not catch the OutOfMemoryError, the Android app crashes. --- src/android/CameraLauncher.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/android/CameraLauncher.java b/src/android/CameraLauncher.java index ec8222d..0dd247b 100755 --- a/src/android/CameraLauncher.java +++ b/src/android/CameraLauncher.java @@ -530,8 +530,20 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect } else { matrix.setRotate(rotate, (float) bitmap.getWidth() / 2, (float) bitmap.getHeight() / 2); } - bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); - exif.resetOrientation(); + + try + { + bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); + exif.resetOrientation(); + } + catch (OutOfMemoryError oom) + { + // You can run out of memory if the image is very large: + // http://simonmacdonald.blogspot.ca/2012/07/change-to-camera-code-in-phonegap-190.html + // If this happens, simply do not rotate the image and return it unmodified. + // If you do not catch the OutOfMemoryError, the Android app crashes. + } + return bitmap; }