Skip to content
Open
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
@@ -1,6 +1,8 @@
package com.existfragger.rnimagesize;

import android.content.ContentResolver;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.ExifInterface;
Expand All @@ -15,11 +17,15 @@
import com.facebook.react.bridge.WritableMap;

import java.io.InputStream;
import java.lang.Integer;
import java.net.URL;

public class RNImageSizeModule extends ReactContextBaseJavaModule {
private final ReactApplicationContext reactContext;

public static final String LOCAL_ASSET_SCHEME = "asset";
public static final String LOCAL_RESOURCE_SCHEME = "res";

public RNImageSizeModule(final ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
Expand Down Expand Up @@ -53,6 +59,20 @@ public void getSize(String uri, final Promise promise) {
// For SCHEME_FILE, Use ExifInterface(String filename) if the SDK version is less than 24(N)
exifInterface = new ExifInterface(u.getPath());
}
} else if (LOCAL_ASSET_SCHEME.equals(scheme)) {
AssetManager assetManager = getReactApplicationContext().getAssets();
String assetName = u.getPath().substring(1);
BitmapFactory.decodeStream(assetManager.open(assetName), null, options);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
exifInterface = new ExifInterface(assetManager.open(assetName));
}
} else if (LOCAL_RESOURCE_SCHEME.equals(scheme)) {
Resources resources = getReactApplicationContext().getResources();
int resourceId = Integer.parseInt(u.getPath().substring(1));
BitmapFactory.decodeStream(resources.openRawResource(resourceId), null, options);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
exifInterface = new ExifInterface(resources.openRawResource(resourceId));
}
} else {
// ContentResolver.openInputStream() cannot handle this scheme, treat it as remote uri
URL url = new URL(uri);
Expand Down