【问题标题】:Issue With Xamarin.Forms Images in iOS RendereriOS 渲染器中的 Xamarin.Forms 图像问题
【发布时间】:2016-04-09 03:20:16
【问题描述】:

我希望有人能帮我解决这个奇怪的问题。

我在 Xamarin Forms 中,在渲染器中。我将Xamarin.Forms.ImageSource 传递给ImageLoaderSourceHandler

var_imageLoader = new ImageLoaderSourceHandler();

但是,当我 await LoadImageAsync 方法时,它总是返回 null,而不是 UIimage

if (_view.Icon?.Source != null)
{
    _iconImageView.Image = 
        await _imageLoader.LoadImageAsync(_view.Icon.Source);
}

我的图像位于Resource 目录中,并且是BundleResource作为构建操作。

文件命名是正确的(menu.png、menu@2x.png、menu@3x.png),如果想法我已经用完了。

有人知道一两个线索吗? 谢谢

【问题讨论】:

  • Dean,你能把代码显示而不是描述吗?
  • 代码量很大,所以我只是添加了相关位

标签: xamarin xamarin.forms


【解决方案1】:

ImageLoaderSourceHandler 用于从 URL 下载图片。

由于您的文件是本地文件,您需要使用FileImageSourceHandler

您可以使用此帮助方法为您找到正确的类型。

private static IImageSourceHandler GetHandler(ImageSource source)
        {
            IImageSourceHandler returnValue = null;
            if (source is UriImageSource)
            {
                returnValue = new ImageLoaderSourceHandler();
            }
            else if (source is FileImageSource)
            {
                returnValue = new FileImageSourceHandler();
            }
            else if (source is StreamImageSource)
            {
                returnValue = new StreamImagesourceHandler();
            }
            return returnValue;
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-09
    • 2023-03-14
    • 2018-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多