Exemplo n.º 1
0
        private void OnImageLoad(object sender, HtmlImageLoadEventArgs e)
        {
            try
            {
                var image = new Bitmap(ChartImageDisplayWidth, ChartImageDisplayHeight);

                using (var graphics = Graphics.FromImage(image))
                {
                    if (HWInfo.SensorTrends.ContainsKey(e.Src))
                    {
                        graphics.DrawLines(_scrollPen, HWInfo.SensorTrends[e.Src].Read(ChartImageDisplayWidth, ChartImageDisplayHeight));
                    }

                    graphics.DrawRectangle(_whitePen,
                                           new Rectangle(0, 0, ChartImageDisplayWidth - 1, ChartImageDisplayHeight - 1));

                    graphics.DrawString(HWInfo.SensorTrends[e.Src].MaxV(), _drawFont, _whiteBrush, (float)1, (float)1);


                    graphics.DrawString(HWInfo.SensorTrends[e.Src].MinV(), _drawFont, _whiteBrush, (float)1, (float)ChartImageDisplayHeight - 17);
                }

                e.Callback(image);
            }
            catch
            {
                var image = new Bitmap(1, 1);

                e.Callback(image);
            }
        }
Exemplo n.º 2
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="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);
            }
        }
Exemplo n.º 3
0
        private void htmlPanel_ImageLoad(object sender, HtmlImageLoadEventArgs e)
        {
            /**
             * Codigo al iniciar el evento de cargar de imagen une la direccion relativa de
             * la carga de imagen y la direccion fisica del capitulo, luego lo busca
             * en el diccionario de imagenes y luego de obtener la imagen carga la imagen.
             * Y la regreso al evento de carga de imagenes.
             */

            string imageFilePath = GetFullPath(capitulo_actual.ContentFileName, e.Src);

            EpubByteContentFile imageContent;

            if (epub.Content.Images.TryGetValue(imageFilePath, out imageContent))
            {
                using (MemoryStream imageStream = new MemoryStream(imageContent.Content))
                {
                    BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.BeginInit();
                    bitmapImage.StreamSource = imageStream;
                    bitmapImage.CacheOption  = BitmapCacheOption.OnLoad;
                    bitmapImage.EndInit();
                    bitmapImage.Freeze();
                    e.Callback(BitmapImage2Bitmap(bitmapImage));
                }
                e.Handled = true;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="src"></param>
        /// <param name="imageLoadEvent"></param>
        protected void LoadImageFromFile(string src, HtmlImageLoadEventArgs imageLoadEvent)
        {
            try
            {
                Uri uri = new Uri(src);
                //Try to load the file as Image from file
                //Remove the scheme first
                string srcWithoutScheme = src;
                int    i = srcWithoutScheme.IndexOf(':');
                if (i > 0)
                {
                    srcWithoutScheme = srcWithoutScheme.Substring(i + 1).TrimStart('/');
                }
                //If not absolute, add the current file path
                if (!Path.IsPathRooted(srcWithoutScheme))
                {
                    uri = new Uri(@"file:///" + this.FileInfo.FileDirectory + "/" + srcWithoutScheme);
                }

                //For SVG images: Convert to Bitmap
                string extension = Path.GetExtension(src);
                if (extension != null && extension.Equals(".svg", StringComparison.OrdinalIgnoreCase))
                {
                    ConvertSvgToBitmap(SvgDocument.Open <SvgDocument>(uri.LocalPath), imageLoadEvent);
                }
                else
                {
                    //Load uri, 8, 1
                    imageLoadEvent.Callback((Bitmap)Image.FromFile(uri.LocalPath, true));
                }
            }
            catch { } //Not able to handle, refer back to orginal process
        }
Exemplo n.º 5
0
        /// <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);
            }
        }
Exemplo n.º 6
0
 /// <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);
     if (!e.Handled)
         YamuiThemeManager.GetHtmlImages(e);
 }
Exemplo n.º 7
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.º 8
0
 /// <summary>
 /// Propagate the image load event from root container.
 /// </summary>
 protected virtual void OnImageLoad(HtmlImageLoadEventArgs e)
 {
     ImageLoad?.Invoke(this, e);
     if (!e.Handled)
     {
         YamuiThemeManager.GetHtmlImages(e);
     }
 }
Exemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="svgDocument"></param>
        /// <param name="imageLoadEvent"></param>
        protected Bitmap ConvertSvgToBitmap(SvgDocument svgDocument, HtmlImageLoadEventArgs imageLoadEvent)
        {
            Bitmap svgImage = new Bitmap((int)svgDocument.Width, (int)svgDocument.Height, PixelFormat.Format32bppArgb);

            svgDocument.Draw(svgImage);
            imageLoadEvent.Callback(svgImage);
            imageLoadEvent.Handled = true;
            return(svgImage);
        }
Exemplo n.º 10
0
        /// <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);
            }
        }
Exemplo n.º 11
0
 private void HtmlPanel_ImageLoad(object sender, HtmlImageLoadEventArgs e)
 {
     if (e.Src.StartsWith(".."))
     {
         var uri  = new Uri(NewsUri);
         var path = new Uri($"{uri.Scheme}://{e.Src.Replace("..", uri.Host)}");
         e.Callback(path.AbsoluteUri);
     }
 }
Exemplo n.º 12
0
        /// <summary>
        /// Feeds the images to the html renderer
        /// </summary>
        internal static void GetHtmlImages(HtmlImageLoadEventArgs e)
        {
            Image img = FindImage(e.Src);

            if (img != null)
            {
                e.Callback(img);
                e.Handled = true;
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Propagate the image load event from root container.
        /// </summary>
        protected virtual void OnImageLoad(HtmlImageLoadEventArgs e)
        {
            YamuiThemeManager.OnHtmlImageLoad(e);
            var handler = ImageLoad;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Exemplo n.º 14
0
 private void OnImageLoad(object sender, HtmlImageLoadEventArgs e)
 {
     if (CheckAccess())
     {
         OnImageLoad(e);
     }
     else
     {
         Dispatcher.UIThread.InvokeAsync(() => OnImageLoad(e)).Wait();
     }
 }
Exemplo n.º 15
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.º 16
0
 private void OnImageLoad(object sender, HtmlImageLoadEventArgs e)
 {
     if (CheckAccess())
     {
         OnImageLoad(e);
     }
     else
     {
         Dispatcher.Invoke(new Action <HtmlImageLoadEventArgs>(OnImageLoad), e);
     }
 }
Exemplo n.º 17
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
     {
         EventHandler <HtmlImageLoadEventArgs> handler = this.ImageLoad;
         if (handler != null)
         {
             handler(this, args);
         }
     }
     catch (Exception ex)
     {
         this.ReportError(HtmlRenderErrorType.Image, "Failed image load event", ex);
     }
 }
Exemplo n.º 18
0
        /// <summary>
        /// Callback from ImageRequestorTask for when an image is retrieved.
        /// </summary>
        /// <param name="image">The image retrieved (may be null)</param>
        /// <param name="parameter">The HtmlImageLoadEventArgs argument</param>
        private void ImageRetrieved(Image image, object parameter)
        {
            HtmlImageLoadEventArgs args = parameter as HtmlImageLoadEventArgs;

            if (args != null)
            {
                args.Callback(image);

                Bounds = new Rectangle(Bounds.X, Bounds.Y, Control.Size.Width, Control.Size.Height + SpaceAfter);

                // Now we have an image, we need to adjust the control height to accommodate the
                // image size the label height will likely have changed.
                _layout.Container.RaiseRelayout();
                _layout.Container.Invalidate();
            }
        }
        /// <summary>
        /// Custom renderer for SVG images in the markdown as not supported natively.
        /// @see https://htmlrenderer.codeplex.com/wikipage?title=Rendering%20SVG%20images
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="imageLoadEvent"></param>
        protected void OnImageLoad(object sender, HtmlImageLoadEventArgs imageLoadEvent)
        {
            try
            {
                //Get some file information
                string src = imageLoadEvent.Src;
                Regex  reg = new Regex("^(file|http|https)://.*");
                if (!reg.IsMatch(src))
                {
                    src = @"file:///" + Regex.Replace(src, @"\?.*", "");                  //remove any params. like "?raw=1" from src
                }
                Uri    uri       = new Uri(src);
                string extension = Path.GetExtension(src);

                //Check if local file or web resource
                switch (uri.Scheme.ToLowerInvariant())
                {
                case "file":
                    //In case of a local file -> Try to load it directly
                    imageLoadEvent.Handled = true;     //Tell the event it was handled, so no error border is drawn
                    ThreadPool.QueueUserWorkItem(state => LoadImageFromFile(src, imageLoadEvent));
                    break;

                case "http":
                case "https":
                    //For web resources check extension and parameter, to fetch from e.g. "badge" creating sources
                    if ((extension != null && extension.Equals(".svg", StringComparison.OrdinalIgnoreCase)) ||
                        uri.ToString().Contains("svg="))
                    {
                        //In case of a web resource file -> Load async
                        using (WebClient webClient = new WebClient())
                        {
                            imageLoadEvent.Handled           = true; //Tell the event it was handled, so no error border is drawn
                            webClient.DownloadDataCompleted += (downloadSender, downloadEvent) => { OnDownloadDataCompleted(downloadEvent, imageLoadEvent); };
                            webClient.DownloadDataAsync(uri);
                        }
                    }
                    break;
                }
            }
            catch
            {
            }
        }
Exemplo n.º 20
0
 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);
 }
Exemplo n.º 21
0
        public static void OnImageLoad(object sender, HtmlImageLoadEventArgs args)
        {
            Console.WriteLine(directory + args.Src);
            if (!_imageSurface.ContainsKey(args.Src))
            {
                var img_surface = SDL_image.IMG_Load(directory + args.Src);
                if (img_surface.ShowSDLError("OnImageLoad: Unable to IMG_Load!"))
                {
                    return;
                }

                _imageSurface[args.Src] = img_surface;
            }
            args.Handled = true;
            //foreach (var kv in args.Attributes)
            //Console.WriteLine("{0}: {1}", kv.Key, kv.Value);

            args.Callback(_imageSurface[args.Src]);
        }
Exemplo n.º 22
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 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>
        /// Feeds the images to the html renderer
        /// </summary>
        internal static void OnHtmlImageLoad(HtmlImageLoadEventArgs e)
        {
            // load image from user
            if (OnHtmlImageNeeded != null)
            {
                OnHtmlImageNeeded(null, e);
                if (e.Handled)
                {
                    return;
                }
            }
            // load image from yamui library
            Image tryImg = (Image)Resources.Resources.ResourceManager.GetObject(e.Src);

            if (tryImg == null)
            {
                return;
            }
            e.Handled = true;
            e.Callback(tryImg);
        }
Exemplo n.º 24
0
        /// <summary>
        /// Custom renderer for SVG images in the markdown as not supported natively.
        /// @see https://htmlrenderer.codeplex.com/wikipage?title=Rendering%20SVG%20images
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="imageLoadEvent"></param>
        protected void OnImageLoad(object sender, HtmlImageLoadEventArgs imageLoadEvent)
        {
            try
            {
                //Get some file information
                string src       = imageLoadEvent.Src;
                Uri    uri       = new Uri(src);
                string extension = Path.GetExtension(src);

                //Check if local file or web resource
                switch (uri.Scheme.ToLowerInvariant())
                {
                case "file":
                    //In case of a local file -> Load directly
                    if (extension != null && extension.Equals(".svg", StringComparison.OrdinalIgnoreCase))
                    {
                        ConvertSvgToBitmap(SvgDocument.Open <SvgDocument>(uri.LocalPath), imageLoadEvent);
                    }
                    break;

                case "http":
                case "https":
                    //For web resources check extension and parameter, to fetch from e.g. "badge" creating sources
                    if ((extension != null && extension.Equals(".svg", StringComparison.OrdinalIgnoreCase)) ||
                        uri.ToString().Contains("svg="))
                    {
                        //In case of a web resource file -> Load async
                        using (WebClient webClient = new WebClient())
                        {
                            webClient.DownloadDataCompleted += (downloadSender, downloadEvent) => { OnDownloadDataCompleted(downloadEvent, imageLoadEvent); };
                            webClient.DownloadDataAsync(uri);
                            imageLoadEvent.Handled = true;
                        }
                    }
                    break;
                }
            } catch
            {
            }
        }
Exemplo n.º 25
0
        /// <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);
            }
        }
Exemplo n.º 26
0
        /// <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);
                }
            }
        }
Exemplo n.º 27
0
        /// <summary>
        /// On image load in renderer set the image by event async.
        /// </summary>
        protected static void OnImageLoad(object sender, HtmlImageLoadEventArgs e)
        {
            var img = TryLoadResourceImage(e.Src);

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

            if (!e.Handled && e.Attributes != null)
            {
                if (e.Attributes.ContainsKey("byevent"))
                {
                    int delay;
                    if (int.TryParse(e.Attributes["byevent"], out delay))
                    {
                        e.Handled = true;
                        System.Threading.ThreadPool.QueueUserWorkItem(state =>
                        {
                            System.Threading.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");
                        });
                    }
                    else
                    {
                        e.Callback("http://sphotos-a.xx.fbcdn.net/hphotos-ash4/c22.0.403.403/p403x403/263440_10152243591765596_773620816_n.jpg");
                    }
                }
                else if (e.Attributes.ContainsKey("byrect"))
                {
                    var split = e.Attributes["byrect"].Split(',');
                    var rect  = new RectI(int.Parse(split[0]), int.Parse(split[1]), int.Parse(split[2]), int.Parse(split[3]));
                    e.Callback(Demo.HtmlRenderer.Resources.html32, rect);
                }
            }
        }
Exemplo n.º 28
0
 /// <summary>
 /// Propagate the image load event from root container.
 /// </summary>
 protected virtual void OnImageLoad(HtmlImageLoadEventArgs e) => RaiseRouted(ImageLoadEvent, e);
Exemplo n.º 29
0
 private void OnImageLoad(object sender, HtmlImageLoadEventArgs e)
 {
     OnImageLoad(e);
 }
Exemplo n.º 30
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="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);
            }
        }
Exemplo n.º 31
0
        /// <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);
        }