Fix exception when trying to resize a file that can't be open on Android

This commit is contained in:
Florian Rival 2015-12-10 17:50:12 +01:00
parent acc5cbb090
commit f3a1cab919
1 changed files with 6 additions and 3 deletions

View File

@ -20,6 +20,10 @@ class ImageResizer {
private static Bitmap resizeImage(String imagePath, int maxWidth, int maxHeight) {
try {
Bitmap image = BitmapFactory.decodeFile(imagePath);
if (image == null) {
return null; // Can't load the image from the given path.
}
if (maxHeight > 0 && maxWidth > 0) {
int width = image.getWidth();
int height = image.getHeight();
@ -34,10 +38,9 @@ class ImageResizer {
finalHeight = (int) ((float) maxWidth / ratioBitmap);
}
image = Bitmap.createScaledBitmap(image, finalWidth, finalHeight, true);
return image;
} else {
return image;
}
return image;
} catch (OutOfMemoryError ex) {
// No memory available for resizing.
}