Reputation: 20451
I hope someone can help me with this weird problem.
I'm in Xamarin Forms, in a renderer. I'm passing a Xamarin.Forms.ImageSource
into a ImageLoaderSourceHandler
.
var_imageLoader = new ImageLoaderSourceHandler();
However, when I await
the LoadImageAsync
method it always returns null, rather than UIimage
.
if (_view.Icon?.Source != null)
{
_iconImageView.Image =
await _imageLoader.LoadImageAsync(_view.Icon.Source);
}
My images are in the Resource
directory and are BundleResource
as build action.
The file naming is correct (menu.png, [email protected], [email protected]) and I've run out if ideas.
Anyone got a clue or two ? Thanks
Upvotes: 1
Views: 562
Reputation: 1858
ImageLoaderSourceHandler
is used if you want to download images from a Url.
Since your files are local you need to use FileImageSourceHandler
You can use this help method to get you the right type.
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;
}
Upvotes: 2