简体   繁体   中英

Display image from gallery using fresco library

I'm using fresco library in my android project and I'm trying to set the image from gallery.

photoHolder = (SimpleDraweeView) view
                        .findViewById(R.id.selectPhoto);

photoHolder.setImageURI(uri);

and this is the value of uri: content://media/external/images/media/987

I get that uri from onActivityResult when I select a photo from the gallery like:

public void onActivityResult(int requestCode, int resultCode, Intent data) {
       ..
    Uri uri = data.getData();
    ...
}

Drawee:

<com.facebook.drawee.view.SimpleDraweeView
            android:id="@+id/profilePic"
            android:layout_width="@dimen/feed_item_profile_pic"
            android:layout_height="@dimen/feed_item_profile_pic"
            android:scaleType="fitCenter"
            />

I don't get any errors but the image is not being displayed.

I tried all that I could find online, but without complaining I don't know what could be wrong with it.

I had the exact same issue with the minor difference of loading images from the app private storage folder.

the .jpg was stored on the path like:

/storage/emulated/0/Android/data/xyz.app.packagename/files/Pictures/24.08.2017 02:36:30.jpg

You can then proceed by checking if your path is a legit File by doing:

File imageFile = new File("/storage/emulated/0/Android/data/xyz.app.packagename/files/Pictures/24.08.2017 02:36:30.jpg");
boolean isValidFile = imageFile.isFile();
if (isValidFile){
    photoHolder.setImageURI(Uri.fromFile(imageFile));
}

Hope this helps someone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM