public override Task <IImageSourceServiceResult?> LoadDrawableAsync(IImageSource imageSource, Android.Widget.ImageView imageView, CancellationToken cancellationToken = default) { var fontImageSource = (IFontImageSource)imageSource; if (!fontImageSource.IsEmpty) { var size = FontManager.GetFontSize(fontImageSource.Font); var unit = fontImageSource.Font.AutoScalingEnabled ? ComplexUnitType.Sp : ComplexUnitType.Dip; var textSize = TypedValue.ApplyDimension(unit, size.Value, imageView.Context?.Resources?.DisplayMetrics); var typeface = FontManager.GetTypeface(fontImageSource.Font); var color = (fontImageSource.Color ?? Graphics.Colors.White).ToPlatform(); var callback = new ImageLoaderCallback(); try { PlatformInterop.LoadImageFromFont( imageView, color, fontImageSource.Glyph, typeface, textSize, callback); return(callback.Result); } catch (Exception ex) { Logger?.LogWarning(ex, "Unable to generate font image '{Glyph}'.", fontImageSource.Glyph); throw; } } return(Task.FromResult <IImageSourceServiceResult?>(null)); }
public override Task <IImageSourceServiceResult?> LoadDrawableAsync(IImageSource imageSource, Android.Widget.ImageView imageView, CancellationToken cancellationToken = default) { var fileImageSource = (IFileImageSource)imageSource; if (!fileImageSource.IsEmpty) { var callback = new ImageLoaderCallback(); try { var id = imageView.Context?.GetDrawableId(fileImageSource.File) ?? -1; if (id > 0) { imageView.SetImageResource(id); return(Task.FromResult <IImageSourceServiceResult?>(new ImageSourceServiceLoadResult())); } else { PlatformInterop.LoadImageFromFile(imageView, fileImageSource.File, callback); } return(callback.Result); } catch (Exception ex) { Logger?.LogWarning(ex, "Unable to load image file '{File}'.", fileImageSource.File); throw; } } return(Task.FromResult <IImageSourceServiceResult?>(null)); }
public override Task <IImageSourceServiceResult?> LoadDrawableAsync(IImageSource imageSource, Android.Widget.ImageView imageView, CancellationToken cancellationToken = default) { var uriImageSource = (IUriImageSource)imageSource; if (!uriImageSource.IsEmpty) { try { var callback = new ImageLoaderCallback(); PlatformInterop.LoadImageFromUri(imageView, uriImageSource.Uri.OriginalString, new Java.Lang.Boolean(uriImageSource.CachingEnabled), callback); return(callback.Result); } catch (Exception ex) { Logger?.LogWarning(ex, "Unable to load image uri '{Uri}'.", uriImageSource.Uri.OriginalString); throw; } } return(Task.FromResult <IImageSourceServiceResult?>(null)); }
public override async Task <IImageSourceServiceResult?> LoadDrawableAsync(IImageSource imageSource, Android.Widget.ImageView imageView, CancellationToken cancellationToken = default) { var streamImageSource = (IStreamImageSource)imageSource; if (!streamImageSource.IsEmpty) { Stream?stream = null; try { stream = await streamImageSource.GetStreamAsync(cancellationToken).ConfigureAwait(false); var callback = new ImageLoaderCallback(); PlatformInterop.LoadImageFromStream(imageView, stream, callback); var result = await callback.Result; stream?.Dispose(); return(result); } catch (Exception ex) { Logger?.LogWarning(ex, "Unable to load image stream."); throw; } finally { if (stream != null) { GC.KeepAlive(stream); } } } return(null); }