在Xamarin.Android中显示的图像

时间:2018-02-15 08:45:03

标签: xamarin.android

我是xamarin和android的新手。我正在尝试创建一个示例应用程序。我想在应用程序中显示一个位图。我已编写代码并成功编译。当我使用模拟器运行它崩溃而我不是能够理解为什么。即使我在它没有击中的方法中设置了断点。

如何调试和理解问题

图像获取方法:

P_ETL_KPI_Fac_DShipment_Launch

我正在使用此方法的代码

 public static Bitmap GetImageBitmapFromUrl(string url)
    {
        Bitmap imageBitmap = null;
        using (var webClient = new WebClient())
        {
            var imageBytes = webClient.DownloadData(url);
            if(imageBytes!=null && imageBytes.Length > 0)
            {
                imageBitmap = BitmapFactory.DecodeByteArray(imageBytes,0,imageBytes.Length);
            }
        }
        return imageBitmap;
    }

我试图通过在imageBitmap上保留断点来调试,看看它可能是null但是没有击中断点。

1 个答案:

答案 0 :(得分:0)

  

在Xamarin.Android中显示的图像

有一些第三方库可以很好地实现此功能,例如PicassoGlide

例如,您可以尝试使用Glide轻松实现此功能:

  1. 下载Glide nuget包:
  2. enter image description here

    1. ImageView控件上显示互联网图片:

      Glide
          .With(this)
          .Load("http://theopentutorials.com/totwp331/wp-content/uploads/totlogo.png")
          .Apply(RequestOptions.CircleCropTransform())
          .Into(imageView);
      
    2. 更新

      您可以在Xamarin.Android Properties中更改目标版本:

      enter image description here enter image description here

      如果您的Android模拟器操作系统版本低于项目最低安卓版本,那么您无法将项目部署到模拟器。