public Task <IBitmap> Load(Stream sourceStream, float?desiredWidth, float?desiredHeight) { var data = NSData.FromStream(sourceStream); var tcs = new TaskCompletionSource <IBitmap>(); #if UIKIT NSRunLoop.InvokeInBackground(() => { try { var bitmap = UIImage.LoadFromData(data); if (bitmap == null) { throw new Exception("Failed to load image"); } tcs.TrySetResult(new CocoaBitmap(bitmap)); } catch (Exception ex) { LogHost.Default.Debug(ex, "Unable to parse the known colour name."); tcs.TrySetException(ex); } }); #else tcs.TrySetResult(new CocoaBitmap(new UIImage(data))); #endif return(tcs.Task); }
/// <inheritdoc /> public Task <IBitmap> Load(Stream sourceStream, float?desiredWidth, float?desiredHeight) { var data = NSData.FromStream(sourceStream); var tcs = new TaskCompletionSource <IBitmap>(); NSRunLoop.Main.BeginInvokeOnMainThread(() => { try { #if UIKIT var bitmap = UIImage.LoadFromData(data); if (bitmap == null) { throw new Exception("Failed to load image"); } tcs.TrySetResult(new CocoaBitmap(bitmap)); #else tcs.TrySetResult(new CocoaBitmap(new UIImage(data))); #endif } catch (Exception ex) { tcs.TrySetException(ex); } }); return(tcs.Task); }