【问题标题】:Display image from gallery using fresco library使用 fresco 库显示来自画廊的图像
【发布时间】:2016-02-06 20:29:44
【问题描述】:

我在我的 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"
            />

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

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

【问题讨论】:

  • 您可以分享您的布局吗?也许那里可能有一些问题。
  • @thetonrifles 那是我的受赠人
  • frescolib.org/docs/troubleshooting.html#troubleshooting。那里有关于如何设置调试日志的说明。
  • 好的,但是这个 SimpleDraweeView 位于哪里?我的意思是...如果您在使用setImageURI 时没有任何错误,则图像可能已正确渲染,但SimpleDraweeView 可能由于其周围的布局问题而不可见。
  • @thetonrifles 我改为滑翔,一切正常。位置不是问题

标签: android android-studio fresco


【解决方案1】:

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

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

希望这对某人有所帮助。

【讨论】:

    猜你喜欢
    • 2014-08-12
    • 1970-01-01
    • 2015-05-25
    • 2022-01-16
    • 1970-01-01
    • 1970-01-01
    • 2019-06-30
    • 2015-03-03
    • 1970-01-01
    相关资源
    最近更新 更多