/// <summary> /// Set image of this image box by analyzing the src attribute.<br/> /// Load the image from inline base64 encoded string.<br/> /// Or from calling property/method on the bridge object that returns image or URL to image.<br/> /// Or from file path<br/> /// Or from URI. /// </summary> /// <remarks> /// File path and URI image loading is executed async and after finishing calling <see cref="ImageLoadComplete"/> /// on the main thread and not thread-pool. /// </remarks> /// <param name="src">the source of the image to load</param> /// <param name="attributes">the collection of attributes on the element to use in event</param> /// <returns>the image object (null if failed)</returns> public void LoadImage(string src, Dictionary <string, string> attributes) { try { var args = new HtmlImageLoadEventArgs(src, attributes, OnHtmlImageLoadEventCallback); _htmlContainer.RaiseHtmlImageLoadEvent(args); _asyncCallback = !_htmlContainer.AvoidAsyncImagesLoading; if (!args.Handled) { if (!string.IsNullOrEmpty(src)) { if (src.StartsWith("data:image", StringComparison.CurrentCultureIgnoreCase)) { SetFromInlineData(src); } else { SetImageFromPath(src); } } else { ImageLoadComplete(false); } } } catch (Exception ex) { _htmlContainer.ReportError(HtmlRenderErrorType.Image, "Exception in handling image source", ex); ImageLoadComplete(false); } }
/// <summary> /// Set image of this image box by analyzing the src attribute.<br/> /// Load the image from inline base64 encoded string.<br/> /// Or from calling property/method on the bridge object that returns image or url to image.<br/> /// Or from file path<br/> /// Or from URI. /// </summary> /// <remarks> /// File path and URI image loading is executed async and after finishing calling <see cref="ImageLoadComplete"/> /// on the main thread and not threadpool. /// </remarks> /// <param name="htmlContainer">the container of the html to handle load image for</param> /// <param name="src">the source of the image to load</param> /// <param name="attributes">the collection of attributes on the element to use in event</param> /// <returns>the image object (null if failed)</returns> public void LoadImage(HtmlContainer htmlContainer, string src, Dictionary <string, string> attributes) { ArgChecker.AssertArgNotNull(htmlContainer, "htmlContainer"); _htmlContainer = htmlContainer; try { var args = new HtmlImageLoadEventArgs(src, attributes, OnHtmlImageLoadEventCallback); _htmlContainer.RaiseHtmlImageLoadEvent(args); if (!args.Handled) { if (!string.IsNullOrEmpty(src)) { if (src.StartsWith("data:image", StringComparison.CurrentCultureIgnoreCase)) { _image = GetImageFromData(src); if (_image == null) { _htmlContainer.ReportError(HtmlRenderErrorType.Image, "Failed extract image from inline data"); } _releaseImageObject = true; ImageLoadComplete(false); } else { SetImageFromPath(src); } } else { ImageLoadComplete(false); } } } catch (Exception ex) { _htmlContainer.ReportError(HtmlRenderErrorType.Image, "Exception in handling image source", ex); ImageLoadComplete(false); } }
/// <summary> /// Set image of this image box by analyzing the src attribute.<br/> /// Load the image from inline base64 encoded string.<br/> /// Or from calling property/method on the bridge object that returns image or url to image.<br/> /// Or from file path<br/> /// Or from URI. /// </summary> /// <remarks> /// File path and URI image loading is executed async and after finishing calling <see cref="ImageLoadComplete"/> /// on the main thread and not thread-pool. /// </remarks> /// <param name="htmlContainer">the container of the html to handle load image for</param> /// <param name="src">the source of the image to load</param> /// <param name="attributes">the collection of attributes on the element to use in event</param> /// <returns>the image object (null if failed)</returns> public void LoadImage(HtmlContainer htmlContainer, string src, Dictionary<string, string> attributes) { ArgChecker.AssertArgNotNull(htmlContainer, "htmlContainer"); _htmlContainer = htmlContainer; try { var args = new HtmlImageLoadEventArgs(src, attributes, OnHtmlImageLoadEventCallback); _htmlContainer.RaiseHtmlImageLoadEvent(args); _asyncCallback = true; if (!args.Handled) { if (!string.IsNullOrEmpty(src)) { if (src.StartsWith("data:image", StringComparison.CurrentCultureIgnoreCase)) { _image = GetImageFromData(src); if (_image == null) _htmlContainer.ReportError(HtmlRenderErrorType.Image, "Failed extract image from inline data"); _releaseImageObject = true; ImageLoadComplete(false); } else { SetImageFromPath(src); } } else { ImageLoadComplete(false); } } } catch (Exception ex) { _htmlContainer.ReportError(HtmlRenderErrorType.Image, "Exception in handling image source", ex); ImageLoadComplete(false); } }