壁画从SD卡加载图像

时间:2018-04-24 16:07:36

标签: android xamarin fresco

我正在使用壁画库,我正在尝试将SD卡中的图像读入图像视图。

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

我收到错误无法输入类型androd.widget.imageview的实例以键入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 ---&gt; Android.Views.InflateException:二进制XML文件行#1:错误膨胀类com.facebook.drawee.view.SimpleDraweeView ---&gt; Java.Lang.Reflect.InvocationTargetException:抛出了类型'Java.Lang.Reflect.InvocationTargetException'的异常。 ---&GT; Java.Lang.NullPointerException:SimpleDraweeView未初始化!

1 个答案:

答案 0 :(得分:0)

错误已经告诉您需要做什么:通过在您的应用程序中调用Fresco.initialize(...)来初始化Fresco,例如

public class MyApplication extends Application {
  @Override
  public void onCreate() {
    super.onCreate();
    Fresco.initialize(this);
  }
}

更多信息:http://frescolib.org/docs/