【问题标题】:Image showing in Xamarin.Android在 Xamarin.Android 中显示的图像
【发布时间】:2018-02-27 15:38:44
【问题描述】:

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

如何调试和理解问题

图片获取方式:

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

我使用此方法的代码

var imageBitmap = ImageHelper.GetImageBitmapFromUrl("http://theopentutorials.com/totwp331/wp-content/uploads/totlogo.png");
hotDogImageView.SetImageBitmap(imageBitmap);

我正在尝试通过在 imageBitmap 处保留断点来进行调试,以查看它可能会为空但断点未命中。

【问题讨论】:

  • 你的问题解决了吗?
  • 我会在我尝试后通知你。现在我切换到另一个任务,所以暂停了这项工作。谢谢你

标签: xamarin.android


【解决方案1】:

在 Xamarin.Android 中显示的图像

有一些第三方库很好地实现了这个功能,比如PicassoGlide

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

  1. 下载Glide nuget 包:

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

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

更新:

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

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

【讨论】:

  • 错误无法安装包“Xamarin.Android.Support.Annotations 25.4.0.2”。您正在尝试将此包安装到以“MonoAndroid,Version=v6.0”为目标的项目中,但该包不包含任何与该框架兼容的程序集引用或内容文件。有关详细信息,请联系包作者。 0
  • 你的项目目标版本是什么?安卓6.0?您需要将目标版本更改为 Android 7.0 或更高版本。
  • 怎么改??我厌倦了将最低 android 版本更改为 Android 7.0 但我无法获得 Emulator 选项来运行项目
  • @NAGASREE,我已经更新了我的答案,你可以检查一下。
  • 我也试过了,但仍然出现同样的错误。在 Visual Studio 中,它一直有模拟器,直到 Android 6 Marshallow
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-30
  • 1970-01-01
相关资源
最近更新 更多