protected override void OnImageLoad(HtmlImageLoadEventArgs e) { byte[] imageContent; if (ChapterContent.Images.TryGetValue(e.Src, out imageContent)) { using (MemoryStream imageStream = new MemoryStream(imageContent)) { BitmapImage bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = imageStream; bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.EndInit(); bitmapImage.Freeze(); e.Callback(bitmapImage); } e.Handled = true; } base.OnImageLoad(e); }
/// <summary> /// This callback is invoked when a remote image is requested. These are identified by image: prefixes on the img /// tag source and are assumed to be http based. We request the image from the ImageRequestorTask in CIXClient and /// provide a callback to be invoked when the image is retrieved. /// </summary> private void LabelOnImageLoad(object sender, HtmlImageLoadEventArgs htmlImageLoadEventArgs) { string realUrl = htmlImageLoadEventArgs.Src; if (realUrl.StartsWith("image:", StringComparison.Ordinal)) { realUrl = "http://" + realUrl.Substring(6); Image image = CIX.ImageRequestorTask.NewRequest(realUrl, Control.MaximumSize.Width/3, MaxHeight, ImageRetrieved, htmlImageLoadEventArgs); if (image != null) { htmlImageLoadEventArgs.Callback(image); } } else if (realUrl.StartsWith("images:", StringComparison.Ordinal)) { realUrl = "https://" + realUrl.Substring(7); Image image = CIX.ImageRequestorTask.NewRequest(realUrl, Control.MaximumSize.Width / 3, MaxHeight, ImageRetrieved, htmlImageLoadEventArgs); if (image != null) { htmlImageLoadEventArgs.Callback(image); } } }
private void OnImageLoad(object sender, HtmlImageLoadEventArgs e) { OnImageLoad(e); }
/// <summary> /// Propagate the image load event from root container. /// </summary> protected virtual void OnImageLoad(HtmlImageLoadEventArgs e) { var handler = ImageLoad; if (handler != null) handler(this, e); }
/// <summary> /// On image load in renderer set the image by event async. /// </summary> public static void ImageLoad(HtmlImageLoadEventArgs e) { var img = TryLoadResourceImage(e.Src); if (!e.Handled && e.Attributes != null) { if (e.Attributes.ContainsKey("byevent")) { int delay; if (Int32.TryParse(e.Attributes["byevent"], out delay)) { e.Handled = true; ThreadPool.QueueUserWorkItem(state => { Thread.Sleep(delay); e.Callback("https://fbcdn-sphotos-a-a.akamaihd.net/hphotos-ak-snc7/c0.44.403.403/p403x403/318890_10151195988833836_1081776452_n.jpg"); }); return; } else { e.Callback("http://sphotos-a.xx.fbcdn.net/hphotos-ash4/c22.0.403.403/p403x403/263440_10152243591765596_773620816_n.jpg"); return; } } else if (e.Attributes.ContainsKey("byrect")) { var split = e.Attributes["byrect"].Split(','); var rect = new Rect(Int32.Parse(split[0]), Int32.Parse(split[1]), Int32.Parse(split[2]), Int32.Parse(split[3])); e.Callback(img ?? TryLoadResourceImage("htmlicon"), rect.X, rect.Y, rect.Width, rect.Height); return; } } if (img != null) e.Callback(img); }
/// <summary> /// On image load in renderer set the image by event async. /// </summary> public static void OnImageLoad(object sender, HtmlImageLoadEventArgs args) { ImageLoad(args); }
/// <summary> /// Raise the image load event with the given event args. /// </summary> /// <param name="args">the event args</param> internal void RaiseHtmlImageLoadEvent(HtmlImageLoadEventArgs args) { try { EventHandler<HtmlImageLoadEventArgs> handler = ImageLoad; if (handler != null) handler(this, args); } catch (Exception ex) { ReportError(HtmlRenderErrorType.Image, "Failed image load event", ex); } }
/// <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> /// On image load in renderer set the image by event async. /// </summary> public static void OnImageLoadPdfSharp(object sender, HtmlImageLoadEventArgs e) { ImageLoad(e, true); }
/// <summary> /// On image load in renderer set the image by event async. /// </summary> public static void OnImageLoad(object sender, HtmlImageLoadEventArgs e) { ImageLoad(e, false); }
/// <summary> /// On image load in renderer set the image by event async. /// </summary> public static void ImageLoad(HtmlImageLoadEventArgs e, bool pdfSharp) { var img = TryLoadResourceImage(e.Src); XImage xImg = null; if (img != null) { using (var ms = new MemoryStream()) { img.Save(ms, img.RawFormat); xImg = img != null ? XImage.FromStream(ms) : null; } } object imgObj; if (pdfSharp) imgObj = xImg; else imgObj = img; if (!e.Handled && e.Attributes != null) { if (e.Attributes.ContainsKey("byevent")) { int delay; if (Int32.TryParse(e.Attributes["byevent"], out delay)) { e.Handled = true; ThreadPool.QueueUserWorkItem(state => { Thread.Sleep(delay); e.Callback("https://fbcdn-sphotos-a-a.akamaihd.net/hphotos-ak-snc7/c0.44.403.403/p403x403/318890_10151195988833836_1081776452_n.jpg"); }); return; } else { e.Callback("http://sphotos-a.xx.fbcdn.net/hphotos-ash4/c22.0.403.403/p403x403/263440_10152243591765596_773620816_n.jpg"); return; } } else if (e.Attributes.ContainsKey("byrect")) { var split = e.Attributes["byrect"].Split(','); var rect = new Rectangle(Int32.Parse(split[0]), Int32.Parse(split[1]), Int32.Parse(split[2]), Int32.Parse(split[3])); e.Callback(imgObj ?? TryLoadResourceImage("htmlicon"), rect.X, rect.Y, rect.Width, rect.Height); return; } } if (img != null) e.Callback(imgObj); }
private void OnImageLoad(object sender, HtmlImageLoadEventArgs e) { if (CheckAccess()) OnImageLoad(e); else Dispatcher.Invoke(new Action<HtmlImageLoadEventArgs>(OnImageLoad), e); }
/// <summary> /// Propagate the image load event from root container. /// </summary> protected virtual void OnImageLoad(HtmlImageLoadEventArgs e) { RoutedEventArgs newEventArgs = new RoutedEvenArgs<HtmlImageLoadEventArgs>(ImageLoadEvent, this, e); RaiseEvent(newEventArgs); }
/// <summary> /// Raise the image load event with the given event args. /// </summary> /// <param name="args">the event args</param> internal void RaiseHtmlImageLoadEvent(HtmlImageLoadEventArgs args) { try { if (ImageLoad != null) { ImageLoad(this, args); } } catch (Exception ex) { ReportError(HtmlRenderErrorType.Image, "Failed image load event", ex); } }