Catch OutOfMemory exceptions on Android
This commit is contained in:
parent
6f5ff49c68
commit
5d187494a3
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue