Example #1
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);
 }
Example #2
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);
         }
     }
 }
        /// <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 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);
        }