Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down