From f3a1cab91901decae84870ed5d530583ad425e17 Mon Sep 17 00:00:00 2001 From: Florian Rival Date: Thu, 10 Dec 2015 17:50:12 +0100 Subject: [PATCH] Fix exception when trying to resize a file that can't be open on Android --- .../main/java/fr/bamlab/rnimageresizer/ImageResizer.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/android/src/main/java/fr/bamlab/rnimageresizer/ImageResizer.java b/android/src/main/java/fr/bamlab/rnimageresizer/ImageResizer.java index 80a2d47..07d4268 100644 --- a/android/src/main/java/fr/bamlab/rnimageresizer/ImageResizer.java +++ b/android/src/main/java/fr/bamlab/rnimageresizer/ImageResizer.java @@ -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. }