Catch OutOfMemory exceptions on Android
This commit is contained in:
parent
6f5ff49c68
commit
5d187494a3
|
@ -18,6 +18,7 @@ import java.util.Date;
|
||||||
class ImageResizer {
|
class ImageResizer {
|
||||||
|
|
||||||
private static Bitmap resizeImage(String imagePath, int maxWidth, int maxHeight) {
|
private static Bitmap resizeImage(String imagePath, int maxWidth, int maxHeight) {
|
||||||
|
try {
|
||||||
Bitmap image = BitmapFactory.decodeFile(imagePath);
|
Bitmap image = BitmapFactory.decodeFile(imagePath);
|
||||||
if (maxHeight > 0 && maxWidth > 0) {
|
if (maxHeight > 0 && maxWidth > 0) {
|
||||||
int width = image.getWidth();
|
int width = image.getWidth();
|
||||||
|
@ -37,6 +38,11 @@ class ImageResizer {
|
||||||
} else {
|
} else {
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
} catch (OutOfMemoryError ex) {
|
||||||
|
// No memory available for resizing.
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Bitmap rotateImage(Bitmap b, float degrees)
|
public static Bitmap rotateImage(Bitmap b, float degrees)
|
||||||
|
@ -53,7 +59,7 @@ class ImageResizer {
|
||||||
b = b2;
|
b = b2;
|
||||||
}
|
}
|
||||||
} catch (OutOfMemoryError ex) {
|
} catch (OutOfMemoryError ex) {
|
||||||
// We have no memory to rotate. Return the original bitmap.
|
// No memory available for rotating. Return the original bitmap.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return b;
|
return b;
|
||||||
|
|
Loading…
Reference in New Issue