简体   繁体   English

使用壁画库显示画廊中的图像

[英]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. 我在我的Android项目中使用了壁画库,并且尝试设置图库中的图像。

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

photoHolder.setImageURI(uri);

and this is the value of uri: content://media/external/images/media/987 这是uri的值: content://media/external/images/media/987

I get that uri from onActivityResult when I select a photo from the gallery like: 当我从图库中选择一张照片时,我从onActivityResult中获得了该uri:

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: .jpg文件存储在以下路径中:

/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. 希望这对某人有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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