mirror of
https://github.com/status-im/react-native-image-resizer.git
synced 2025-02-17 17:17:25 +00:00
Fix exception when trying to resize a file that can't be open on Android
This commit is contained in:
parent
acc5cbb090
commit
f3a1cab919
@ -20,6 +20,10 @@ class ImageResizer {
|
|||||||
private static Bitmap resizeImage(String imagePath, int maxWidth, int maxHeight) {
|
private static Bitmap resizeImage(String imagePath, int maxWidth, int maxHeight) {
|
||||||
try {
|
try {
|
||||||
Bitmap image = BitmapFactory.decodeFile(imagePath);
|
Bitmap image = BitmapFactory.decodeFile(imagePath);
|
||||||
|
if (image == null) {
|
||||||
|
return null; // Can't load the image from the given path.
|
||||||
|
}
|
||||||
|
|
||||||
if (maxHeight > 0 && maxWidth > 0) {
|
if (maxHeight > 0 && maxWidth > 0) {
|
||||||
int width = image.getWidth();
|
int width = image.getWidth();
|
||||||
int height = image.getHeight();
|
int height = image.getHeight();
|
||||||
@ -34,10 +38,9 @@ class ImageResizer {
|
|||||||
finalHeight = (int) ((float) maxWidth / ratioBitmap);
|
finalHeight = (int) ((float) maxWidth / ratioBitmap);
|
||||||
}
|
}
|
||||||
image = Bitmap.createScaledBitmap(image, finalWidth, finalHeight, true);
|
image = Bitmap.createScaledBitmap(image, finalWidth, finalHeight, true);
|
||||||
return image;
|
|
||||||
} else {
|
|
||||||
return image;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return image;
|
||||||
} catch (OutOfMemoryError ex) {
|
} catch (OutOfMemoryError ex) {
|
||||||
// No memory available for resizing.
|
// No memory available for resizing.
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user