1

我在我的 android 项目中使用 fresco 库,我正在尝试从图库中设置图像。

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

photoHolder.setImageURI(uri);

这是 uri 的值:content://media/external/images/media/987

当我从图库中选择一张照片时,我会从 onActivityResult 获得该 uri,例如:

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

收款人:

<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"
            />

我没有收到任何错误,但没有显示图像。

我尝试了所有可以在网上找到的方法,但没有抱怨,我不知道它有什么问题。

4

1 回答 1

2

从应用程序私有存储文件夹加载图像的细微差别,我遇到了完全相同的问题。

.jpg 存储在路径上,例如:

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

然后,您可以通过执行以下操作检查您的路径是否是合法文件:

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));
}

希望这可以帮助某人。

于 2017-08-24T00:52:29.437 回答