mirror of
https://github.com/apache/cordova-plugin-camera.git
synced 2025-02-22 04:52:51 +08:00
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:
parent
34e85810c8
commit
6f4fef8479
@ -530,8 +530,20 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
|
|||||||
} else {
|
} else {
|
||||||
matrix.setRotate(rotate, (float) bitmap.getWidth() / 2, (float) bitmap.getHeight() / 2);
|
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;
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user