async void setTitleImage(ParentingViewController pack, FileImageSource titleIcon) { var source = Internals.Registrar.Registered.GetHandler <IImageSourceHandler>(titleIcon.GetType()); var image = await source.LoadImageAsync(titleIcon); //UIImage ctor throws on file not found if MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure is true; pack.NavigationItem.TitleView = new UIImageView(image); }
async void UpdateImage() { IImageSourceHandler handler; FileImageSource source = Element.Image; if (source != null && (handler = Registrar.Registered.GetHandler <IImageSourceHandler>(source.GetType())) != null) { UIImage uiimage; try { uiimage = await handler.LoadImageAsync(source, scale : (float)UIScreen.MainScreen.Scale); } catch (OperationCanceledException) { uiimage = null; } UIButton button = Control; if (button != null && uiimage != null) { if (Forms.IsiOS7OrNewer) { button.SetImage(uiimage.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), UIControlState.Normal); } else { button.SetImage(uiimage, UIControlState.Normal); } button.ImageView.ContentMode = UIViewContentMode.ScaleAspectFit; ComputeEdgeInsets(Control, Element.ContentLayout); } } else { Control.SetImage(null, UIControlState.Normal); ClearEdgeInsets(Control); } ((IVisualElementController)Element).NativeSizeChanged(); }
async void UpdateImage() { IImageSourceHandler handler; FileImageSource source = Element.Image; if (source != null && (handler = Registrar.Registered.GetHandler <IImageSourceHandler>(source.GetType())) != null) { NSImage uiimage; try { uiimage = await handler.LoadImageAsync(source); } catch (OperationCanceledException) { uiimage = null; } NSButton button = Control; if (button != null && uiimage != null) { button.Image = uiimage; if (!string.IsNullOrEmpty(button.Title)) { button.ImagePosition = Element.ToNSCellImagePosition(); } } } ((IVisualElementController)Element).NativeSizeChanged(); }
internal static Drawable GetFormsDrawable(this Context context, FileImageSource fileImageSource) { var file = fileImageSource.File; Drawable drawable = context.GetDrawable(fileImageSource); if (drawable == null) { var bitmap = GetBitmap(context.Resources, file) ?? BitmapFactory.DecodeFile(file); if (bitmap == null) { var source = Registrar.Registered.GetHandler <IImageSourceHandler>(fileImageSource.GetType()); bitmap = source.LoadImageAsync(fileImageSource, context).GetAwaiter().GetResult(); } if (bitmap != null) { drawable = new BitmapDrawable(context.Resources, bitmap); } } return(drawable); }
async void UpdateImage() { IImageSourceHandler handler; FileImageSource source = Element.Image; if (source != null && (handler = Xamarin.Forms.Internals.Registrar.Registered.GetHandler <IImageSourceHandler>(source.GetType())) != null) { string uiimage; try { uiimage = await handler.LoadImageAsync(source, scale : 1.0f); } catch (OperationCanceledException) { uiimage = null; } var Button = Control; if (Button != null && uiimage != null) { Button.Style.BackgroundImage = uiimage; Button.Style.BackgroundPosition = "center"; } } else { Control.Style.BackgroundImage = null; Control.Style.BackgroundPosition = null; } ((IVisualElementController)Element).NativeSizeChanged(); }