public Task <IBitmap> LoadFromResource(string source, float?desiredWidth, float?desiredHeight) { var tcs = new TaskCompletionSource <IBitmap>(); UIApplication.SharedApplication.InvokeOnMainThread(() => { try { #if UIKIT var bitmap = UIImage.FromBundle(source); #else var bitmap = UIImage.ImageNamed(source); #endif if (bitmap == null) { throw new Exception("Failed to load image from resource: " + source); } tcs.TrySetResult(new CocoaBitmap(bitmap)); } catch (Exception ex) { tcs.TrySetException(ex); } }); return(tcs.Task); }
private async Task <DataResolverResult> ResolveFromNamedResourceAsync(string fileName, string identifier, TaskParameter parameters, CancellationToken token) { PImage image = null; try { #if __IOS__ || __TVOS__ await ImageService.Instance.Config.MainThreadDispatcher.PostAsync(() => image = PImage.FromBundle(identifier)).ConfigureAwait(false); #elif __MACOS__ await ImageService.Instance.Config.MainThreadDispatcher.PostAsync(() => image = PImage.ImageNamed(identifier)).ConfigureAwait(false); #endif } catch { } if (image == null && fileName != identifier) { try { #if __IOS__ || __TVOS__ await ImageService.Instance.Config.MainThreadDispatcher.PostAsync(() => image = PImage.FromBundle(fileName)).ConfigureAwait(false); #elif __MACOS__ await ImageService.Instance.Config.MainThreadDispatcher.PostAsync(() => image = PImage.ImageNamed(fileName)).ConfigureAwait(false); #endif } catch { } } if (image != null) { token.ThrowIfCancellationRequested(); var imageInformation = new ImageInformation(); imageInformation.SetPath(identifier); imageInformation.SetFilePath(null); var container = new DecodedImage <object>() { Image = image }; var result = new DataResolverResult(container, LoadingResult.CompiledResource, imageInformation); return(result); } return(null); }
/// <summary> /// Initializes a new instance of the <see cref="Rotation.SourceListItem"/> class. /// </summary> /// <param name="title">Title.</param> /// <param name="icon">Icon.</param> public SourceListItem(string title, string icon) { // Initialize this._title = title; this._icon = NSImage.ImageNamed(icon); }