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. Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/commit/6f4fef84 Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/tree/6f4fef84 Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/diff/6f4fef84 Branch: refs/heads/master Commit: 6f4fef8479d690b9037baa05ab4269f9279e1d80 Parents: 34e8581 Author: Kevin Woram <[email protected]> Authored: Wed Oct 2 16:58:41 2013 -0500 Committer: Andrew Grieve <[email protected]> Committed: Fri Dec 6 14:50:59 2013 -0500 ---------------------------------------------------------------------- src/android/CameraLauncher.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugin-camera/blob/6f4fef84/src/android/CameraLauncher.java ---------------------------------------------------------------------- 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; }
