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.
This commit is contained in:
Kevin Woram 2013-10-02 16:58:41 -05:00 committed by Andrew Grieve
parent 34e85810c8
commit 6f4fef8479

View File

@ -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;
}