private void DrawImage(PageImage pi, Xwt.Drawing.Context g, Xwt.Rectangle r)
        {
            System.IO.MemoryStream ms = new System.IO.MemoryStream(pi.ImageData);
            Xwt.Drawing.Image      im = null;
            try
            {
                // Xwt.Drawing.Image.FromStream does not work.  It crashes with both wpf and gtk
                // As a work around save the image to a temporary file and load it into xwt using the
                // FromFile method.


                System.Drawing.Image img = System.Drawing.Image.FromStream(ms);

                string fileName = System.IO.Path.GetTempFileName();
                img.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);

                //im = Xwt.Drawing.Image.FromStream(ms);
                im = Xwt.Drawing.Image.FromFile(fileName);
                DrawImageSized(pi, im, g, r);

                im.Dispose();
                System.IO.File.Delete(fileName);
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex);
            }
            finally
            {
                if (im != null)
                {
                    im.Dispose();
                }
            }
        }
Пример #2
0
        private void LoadPixbufs()
        {
            int width, height;

            Icon.SizeLookup(icon_size, out width, out height);

            if (normal_pixbuf != null)
            {
                normal_pixbuf.Dispose();
                normal_pixbuf = null;
            }

            if (active_pixbuf != null)
            {
                active_pixbuf.Dispose();
                active_pixbuf = null;
            }

            for (int i = 0; i < icon_names.Length; i++)
            {
                try {
                    normal_pixbuf = ImageService.GetIcon(icon_names[i], icon_size);
                    active_pixbuf = normal_pixbuf;
                    break;
                } catch {
                }
            }

            UpdateImage();
        }
Пример #3
0
 protected override void OnDestroyed()
 {
     if (!hasInactiveImage && inactiveImage != null)
     {
         inactiveImage.Dispose();
     }
     base.OnDestroyed();
 }
Пример #4
0
 protected override void OnDestroyed()
 {
     isDestroyed = true;
     MessageService.PopupDialog -= HandlePopupDialog;
     base.OnDestroyed();
     if (bitmap != null)
     {
         bitmap.Dispose();
         bitmap = null;
     }
     if (monitor != null)
     {
         monitor.Dispose();
         monitor = null;
     }
 }
Пример #5
0
 private void DrawImage(PageImage pi, Xwt.Drawing.Context g, Xwt.Rectangle r)
 {
     System.IO.MemoryStream ms = new System.IO.MemoryStream(pi.ImageData);
     Xwt.Drawing.Image      im = null;
     try
     {
         im = Xwt.Drawing.Image.FromStream(ms);
         DrawImageSized(pi, im, g, r);
     }
     finally
     {
         if (im != null)
         {
             im.Dispose();
         }
     }
 }
Пример #6
0
        protected override void OnDestroyed()
        {
            base.OnDestroyed();

            if (btnNormal != null)
            {
                btnNormal.Dispose();
                btnNormal = null;
            }

            if (iconRunNormal != null)
            {
                iconRunNormal.Dispose();
                iconRunNormal = null;
            }

            if (iconRunDisabled != null)
            {
                iconRunDisabled.Dispose();
                iconRunDisabled = null;
            }

            if (iconStopNormal != null)
            {
                iconStopNormal.Dispose();
                iconStopNormal = null;
            }

            if (iconStopDisabled != null)
            {
                iconStopDisabled.Dispose();
                iconStopDisabled = null;
            }

            if (iconBuildNormal != null)
            {
                iconBuildNormal.Dispose();
                iconBuildNormal = null;
            }

            if (iconBuildDisabled != null)
            {
                iconBuildDisabled.Dispose();
                iconBuildDisabled = null;
            }
        }
Пример #7
0
        // render all the objects in a page (or any composite object
        private void ProcessPage(System.Drawing.Graphics g, IEnumerable p)
        {
            // TODO: (Peter) Support can grow and can shrink
            foreach (PageItem pi in p)
            {
                if (pi is PageTextHtml)
                {       // PageTextHtml is actually a composite object (just like a page)
                    ProcessHtml(pi as PageTextHtml, g);
                    continue;
                }

                if (pi is PageLine)
                {
                    PageLine pl = pi as PageLine;
                    DrawLine(pl.SI.BColorLeft, pl.SI.BStyleLeft, pl.SI.BWidthLeft,
                             g, PixelsX(pl.X + _left - _hScroll), PixelsY(pl.Y + _top - _vScroll),
                             PixelsX(pl.X2 + _left - _hScroll), PixelsY(pl.Y2 + _top - _vScroll));
                    continue;
                }


                RectangleF rect = new RectangleF(PixelsX(pi.X + _left - _hScroll), PixelsY(pi.Y + _top - _vScroll),
                                                 PixelsX(pi.W), PixelsY(pi.H));


                if ((pi is PagePolygon) || (pi is PageCurve))
                { // intentionally empty; polygon's rectangles aren't calculated
                }

                if (pi.SI.BackgroundImage != null)
                {       // put out any background image
                    PageImage i = pi.SI.BackgroundImage;
                    DrawImageBackground(i, pi.SI, g, rect);
                }

                if (pi is PageText)
                {
                    // TODO: enable can shrink, can grow
                    // 2005 spec file, page 9, in the text box has
                    // CanGrow and CanShrink
                    PageText pt = pi as PageText;
                    DrawString(pt, g, rect);
                }
                else if (pi is PageImage)
                {
                    PageImage i = pi as PageImage;
                    DrawImage(i, g, rect);
                }
                else if (pi is PageRectangle)
                {
                    this.DrawBackground(g, rect, pi.SI);
                }
                else if (pi is PageEllipse)
                {
                    PageEllipse pe = pi as PageEllipse;
                    DrawEllipse(pe, g, rect);
                }
                else if (pi is PagePie)
                {
                    PagePie pp = pi as PagePie;
                    DrawPie(pp, g, rect);
                }
                else if (pi is PagePolygon)
                {
                    PagePolygon ppo = pi as PagePolygon;
                    FillPolygon(ppo, g, rect);
                }
                else if (pi is PageCurve)
                {
                    PageCurve pc = pi as PageCurve;
                    DrawCurve(pc.SI.BColorLeft, pc.SI.BStyleLeft, pc.SI.BWidthLeft,
                              g, pc.Points, pc.Offset, pc.Tension);
                }


                DrawBorder(pi, g, rect);
            }

            // TO: convert System.Drawing.Graphics to Xwt.Drawing.Context and draw it to this.g

            Bitmap bm = new Bitmap(gImg.Width, gImg.Height);

            g.DrawImage(bm, gImg.Width, gImg.Height);


            // Xwt.Drawing.Image.FromStream does not work.  It crashes with both wpf and gtk
            // As a work around save the image to a temporary file and load it into xwt using the
            // FromFile method.

            System.IO.MemoryStream s = new System.IO.MemoryStream();
            gImg.Save(s, System.Drawing.Imaging.ImageFormat.Png);
            string fileName = System.IO.Path.GetTempFileName();

            gImg.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);

            // Xwt.Drawing.Image img = Xwt.Drawing.Image.FromStream(s);

            Xwt.Drawing.Image img = Xwt.Drawing.Image.FromFile(fileName);
            xwtContext.DrawImage(img, new Xwt.Rectangle(0, 0, gImg.Width, gImg.Height), new Xwt.Rectangle(0, 0, gImg.Width, gImg.Height));
            img.Dispose();
            System.IO.File.Delete(fileName);
        }