Catch OutOfMemory exceptions on Android

This commit is contained in:
Florian Rival 2015-12-10 17:34:12 +01:00
parent 6f5ff49c68
commit 5d187494a3
1 changed files with 22 additions and 16 deletions

View File

@ -18,6 +18,7 @@ import java.util.Date;
class ImageResizer {
private static Bitmap resizeImage(String imagePath, int maxWidth, int maxHeight) {
try {
Bitmap image = BitmapFactory.decodeFile(imagePath);
if (maxHeight > 0 && maxWidth > 0) {
int width = image.getWidth();
@ -37,6 +38,11 @@ class ImageResizer {
} else {
return image;
}
} catch (OutOfMemoryError ex) {
// No memory available for resizing.
}
return null;
}
public static Bitmap rotateImage(Bitmap b, float degrees)
@ -53,7 +59,7 @@ class ImageResizer {
b = b2;
}
} catch (OutOfMemoryError ex) {
// We have no memory to rotate. Return the original bitmap.
// No memory available for rotating. Return the original bitmap.
}
}
return b;