From 8a8f1007aea6328fe2321004e636d3dd1e43f568 Mon Sep 17 00:00:00 2001 From: grassick Date: Wed, 14 Feb 2018 10:04:48 -0500 Subject: [PATCH] Allow loading from image gallery --- .../com/raananw/ImageResizer/ImageResizePlugin.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Android/com/raananw/ImageResizer/ImageResizePlugin.java b/src/Android/com/raananw/ImageResizer/ImageResizePlugin.java index 478d9c1..07a7781 100644 --- a/src/Android/com/raananw/ImageResizer/ImageResizePlugin.java +++ b/src/Android/com/raananw/ImageResizer/ImageResizePlugin.java @@ -28,9 +28,11 @@ import org.json.JSONException; import org.json.JSONObject; +import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Matrix; +import android.net.Uri; import android.os.Environment; import android.util.Base64; import android.util.Log; @@ -98,9 +100,9 @@ protected Bitmap getBitmap(String imageData, String imageDataType, BitmapFactory byte[] blob = Base64.decode(imageData, Base64.DEFAULT); bmp = BitmapFactory.decodeByteArray(blob, 0, blob.length, options); } else { - URI uri = new URI(imageData); - File imageFile = new File(uri); - bmp = BitmapFactory.decodeFile(imageFile.getAbsolutePath(), options); + Uri uri = Uri.parse(imageData); + Context context = ImageResizePlugin.this.cordova.getActivity().getApplicationContext(); + bmp = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(uri), null, options); } return bmp; }