void LoadIconImage(IImageSourceHandler handler, ImageSource source) { _iconTokenSource = new CancellationTokenSource(); var token = _iconTokenSource.Token; UIImage image = null; var scale = (float)UIScreen.MainScreen.Scale; Task.Run(async() => { if (source is FontImageSource) { DispatchQueue.MainQueue.DispatchSync(async() => { image = await handler.LoadImageAsync(source, token, scale: scale); }); } else { image = await handler.LoadImageAsync(source, token, scale: scale); } token.ThrowIfCancellationRequested(); }, token).ContinueWith(t => { if (t.IsCompleted) { ImageCacheController.Instance.SetObjectforKey(image, FromObject(CellBase.IconSource.GetHashCode())); BeginInvokeOnMainThread(() => { IconView.Image = image; SetNeedsLayout(); }); } }); }
void LoadIconImage(IImageSourceHandler handler, ImageSource source) { _iconTokenSource = new CancellationTokenSource(); var token = _iconTokenSource.Token; Bitmap image = null; var scale = (float)_Context.Resources.DisplayMetrics.Density; Task.Run(async() => { image = await handler.LoadImageAsync(source, _Context, token); token.ThrowIfCancellationRequested(); image = CreateRoundImage(image); }, token).ContinueWith(t => { if (t.IsCompleted) { //entrust disposal of returned old image to Android OS. ImageCacheController.Instance.Put(CellBase.IconSource.GetHashCode(), image); Device.BeginInvokeOnMainThread(() => { Task.Delay(50); // in case repeating the same source, sometimes the icon not be shown. by inserting delay it be shown. IconView.SetImageBitmap(image); Invalidate(); }); } }); }
private async void UpdateImage() { IImageSourceHandler imageSourceHandler = Registrar.Registered.GetHandler <IImageSourceHandler> (Element.Image.GetType()); if (Element.Image != null && imageSourceHandler != null) { NSImage image2; try { image2 = await imageSourceHandler.LoadImageAsync(Element.Image, new CancellationToken()); } catch (OperationCanceledException ex) { image2 = null; } if (Control != null && image2 != null) { Control.Image = image2; //Control.ImageView.ContentMode = UIViewContentMode.ScaleAspectFit; //this.Control.ImageEdgeInsets = new UIEdgeInsets ((nfloat)0, (nfloat)0, (nfloat)0, (nfloat)10); //this.Control.TitleEdgeInsets = new UIEdgeInsets ((nfloat)0, (nfloat)10, (nfloat)0, (nfloat)0); } } else { this.Control.Image = null; //this.Control.ImageEdgeInsets = new UIEdgeInsets ((nfloat)0, (nfloat)0, (nfloat)0, (nfloat)0); //this.Control.TitleEdgeInsets = new UIEdgeInsets ((nfloat)0, (nfloat)0, (nfloat)0, (nfloat)0); } ((IVisualElementController)Element).NativeSizeChanged(); }
async void SetImage(CustomSwitchCell cell, CellTableViewCell target) { var source = cell.ImageSource; target.ImageView.Image = null; IImageSourceHandler handler = GetHandler(source); if (source != null && handler != null) { UIImage uiimage; try { uiimage = await handler.LoadImageAsync(source).ConfigureAwait(false); } catch (TaskCanceledException) { uiimage = null; } NSRunLoop.Main.BeginInvokeOnMainThread(() => { target.ImageView.Image = uiimage; target.SetNeedsLayout(); }); } else { target.ImageView.Image = null; } }
private async Task <Gdk.Pixbuf> LoadImageAsync(ImageSource imageSource) { IImageSourceHandler handler = Registrar.Registered.GetHandler <IImageSourceHandler>(imageSource.GetType()); var image = await handler.LoadImageAsync(imageSource); return(image); }
public async void Share(string subject, string message, ImageSource imageSource) { var intent = new Intent(Intent.ActionSend); intent.SetType("image/jpeg"); if (imageSource is FileImageSource) { handler = new FileImageSourceHandler(); } else if (imageSource is StreamImageSource) { handler = new StreamImagesourceHandler(); // sic } else if (imageSource is UriImageSource) { handler = new ImageLoaderSourceHandler(); // sic } else { } var bitmap = await handler.LoadImageAsync(imageSource, CrossCurrentActivity.Current.Activity); Java.IO.File path = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads + Java.IO.File.Separator + "MyDiagram.jpg"); using (System.IO.FileStream os = new System.IO.FileStream(path.AbsolutePath, System.IO.FileMode.Create)) { bitmap.Compress(Bitmap.CompressFormat.Jpeg, 100, os); } intent.AddFlags(ActivityFlags.GrantReadUriPermission); intent.AddFlags(ActivityFlags.GrantWriteUriPermission); intent.PutExtra(Intent.ExtraStream, FileProvider.GetUriForFile(CrossCurrentActivity.Current.Activity, "com.companyname.ecomdemo.fileprovider", path)); CrossCurrentActivity.Current.Activity.StartActivity(Intent.CreateChooser(intent, "Share Image")); }
private async Task UpdateHamburguerIconAsync() { var hamburguerIcon = Page.Master.Icon; if (hamburguerIcon != null) { IImageSourceHandler handler = Registrar.Registered.GetHandler <IImageSourceHandler>(hamburguerIcon.GetType()); var image = await handler.LoadImageAsync(hamburguerIcon); Widget.UpdateHamburguerIcon(image); var navigationPage = Page.Detail as NavigationPage; if (navigationPage != null) { var navigationRenderer = Platform.GetRenderer(navigationPage) as IToolbarTracker; navigationRenderer?.NativeToolbarTracker.UpdateToolBar(); } } }
public static Task <UIImage> ToUIImage(this ImageSource imageSource) { IImageSourceHandler handler = imageSource.GetHandler(); return(handler.LoadImageAsync(imageSource)); }