android - Fresco 从 sdcard 加载图像
问题描述
我正在使用 fresco 库,并且正在尝试将 sd 卡中的图像读取到 imageview 中。
var CatalogCategories = System.IO.Path.Combine(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryPictures).ToString(), "dbsoft");
SimpleDraweeView draweeView = FindViewById<SimpleDraweeView>(Resource.Id.MainImageView);
Android.Net.Uri imageUri = Android.Net.Uri.FromFile(new Java.IO.File(CatalogCategories, "Main.jpg"));// For files on device
draweeView.SetImageURI(imageUri);
我收到错误 Unable t oconvert instance of type androd.widget.imageview to type Com.Facebook.Drawee.View.SimpleDraweeView
如果我将 Imageview 更改为
<com.facebook.drawee.view.SimpleDraweeView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/MainImageView" />
然后我收到错误
Android.Views.InflateException:二进制 XML 文件第 1 行:二进制 XML 文件第 1 行:膨胀类 com.facebook.drawee.view.SimpleDraweeView ---> Android.Views.InflateException:二进制 XML 文件第 1 行:错误膨胀类 com.facebook.drawee.view.SimpleDraweeView ---> Java.Lang.Reflect.InvocationTargetException:抛出了“Java.Lang.Reflect.InvocationTargetException”类型的异常。---> Java.Lang.NullPointerException: SimpleDraweeView 未初始化!
解决方案
该错误已经告诉您需要做什么:通过调用Fresco.initialize(...)
您的应用程序来初始化 Fresco,例如
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Fresco.initialize(this);
}
}
更多信息: http: //frescolib.org/docs/
推荐阅读
- flutter - 在颤动中滚动 SliverAppBar 时状态栏变为透明
- shiny - 如何在闪亮的应用程序中最小化侧边栏布局?
- python - 如何在 Python 中使用 pandas Dataframe 创建条形图
- java - 性格问题
- medical-imaging - 使用 sitk.Write 保存/写入相同的 dicom 图像后在辐射查看器中看到的输出差异
- php - 确定一天是否已经过去 PHP
- javascript - 获取页面上链接的标题并将它们作为标题属性插入
- r - 根据两组变量在R中创建新变量
- arrays - 从散列数组中过滤值并将它们从原始数组中删除
- python - python kivy 屏幕配置