diff --git a/android/src/main/java/com/existfragger/rnimagesize/RNImageSizeModule.java b/android/src/main/java/com/existfragger/rnimagesize/RNImageSizeModule.java index bc0baf2..6cc36a1 100644 --- a/android/src/main/java/com/existfragger/rnimagesize/RNImageSizeModule.java +++ b/android/src/main/java/com/existfragger/rnimagesize/RNImageSizeModule.java @@ -22,44 +22,48 @@ public RNImageSizeModule(final ReactApplicationContext reactContext) { @ReactMethod public void getSize(String uri, final Promise promise) { - try { - Uri u = Uri.parse(uri); - BitmapFactory.Options options = new BitmapFactory.Options(); - options.inJustDecodeBounds = true; + new Thread(new Runnable() { + public void run() { + try { + Uri u = Uri.parse(uri); + BitmapFactory.Options options = new BitmapFactory.Options(); + options.inJustDecodeBounds = true; - int height = 0; - int width = 0; - int rotation = 0; + int height = 0; + int width = 0; + int rotation = 0; - if (uri.startsWith("file://")) { - BitmapFactory.decodeFile(u.getPath(), options); - ExifInterface exifInterface = new ExifInterface(u.getPath()); - int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); - if (orientation == ExifInterface.ORIENTATION_ROTATE_90) - rotation = 90; - else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) - rotation = 180; - else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) - rotation = 270; - height = options.outHeight; - width = options.outWidth; - } else { - URL url = new URL(uri); - Bitmap bitmap = BitmapFactory.decodeStream((InputStream) url.getContent()); - height = bitmap.getHeight(); - width = bitmap.getWidth(); - } + if (uri.startsWith("file://")) { + BitmapFactory.decodeFile(u.getPath(), options); + ExifInterface exifInterface = new ExifInterface(u.getPath()); + int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); + if (orientation == ExifInterface.ORIENTATION_ROTATE_90) + rotation = 90; + else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) + rotation = 180; + else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) + rotation = 270; + height = options.outHeight; + width = options.outWidth; + } else { + URL url = new URL(uri); + Bitmap bitmap = BitmapFactory.decodeStream((InputStream) url.getContent()); + height = bitmap.getHeight(); + width = bitmap.getWidth(); + } - WritableMap map = Arguments.createMap(); + WritableMap map = Arguments.createMap(); - map.putInt("height", height); - map.putInt("width", width); - map.putInt("rotation", rotation); + map.putInt("height", height); + map.putInt("width", width); + map.putInt("rotation", rotation); - promise.resolve(map); - } catch (Exception e) { - promise.reject(e); - } + promise.resolve(map); + } catch (Exception e) { + promise.reject(e); + } + } + }).start(); } @Override