Exemplo n.º 1
0
        /// <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);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Propagate the image load event from root container.
 /// </summary>
 private void OnImageLoad(object sender, HtmlImageLoadEventArgs e)
 {
     if (ImageLoad != null)
     {
         ImageLoad(this, e);
     }
 }
Exemplo n.º 3
0
 /// <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);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// On image load in renderer set the image by event async.
        /// </summary>
        private static void OnImageLoad(object sender, HtmlImageLoadEventArgs e)
        {
            var img = TryLoadResourceImage(e.Src);

            if(!e.Handled && e.Attributes != null)
            {
                if (e.Attributes.ContainsKey("byevent"))
                {
                    int delay;
                    if (int.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(int.Parse(split[0]), int.Parse(split[1]), int.Parse(split[2]), int.Parse(split[3]));
                    e.Callback( img ?? Resources.html32, rect);
                    return;
                }
            }

            if (img != null)
                e.Callback(img);
        }