Render() public method

Renders the SvgDocument.
public Render ( ISvgDocument node ) : Bitmap
node ISvgDocument /// The SvgDocument node to be /// rendered ///
return System.Drawing.Bitmap
        public override void Render(ISvgRenderer renderer)
        {
            GraphicsWrapper graphics = ((GdiRenderer)renderer).GraphicsWrapper;
            SvgImageElement iElement = (SvgImageElement)element;
            //HttpResource resource = iElement.ReferencedResource;

            /*if (resource != null )
             * {*/
            ImageAttributes imageAttributes = new ImageAttributes();

            string sOpacity = iElement.GetPropertyValue("opacity");

            if (sOpacity.Length > 0)
            {
                double      opacity       = SvgNumber.ParseToFloat(sOpacity);
                ColorMatrix myColorMatrix = new ColorMatrix();
                myColorMatrix.Matrix00 = 1.00f;                         // Red
                myColorMatrix.Matrix11 = 1.00f;                         // Green
                myColorMatrix.Matrix22 = 1.00f;                         // Blue
                myColorMatrix.Matrix33 = (float)opacity;                // alpha
                myColorMatrix.Matrix44 = 1.00f;                         // w

                imageAttributes.SetColorMatrix(myColorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
            }

            float width  = (float)iElement.Width.AnimVal.Value;
            float height = (float)iElement.Height.AnimVal.Value;

            Rectangle destRect = new Rectangle();

            destRect.X      = Convert.ToInt32(iElement.X.AnimVal.Value);
            destRect.Y      = Convert.ToInt32(iElement.Y.AnimVal.Value);
            destRect.Width  = Convert.ToInt32(width);
            destRect.Height = Convert.ToInt32(height);

            Image image;

            if (iElement.IsSvgImage)
            {
                SvgWindow wnd = getSvgWindow();
                gdiRenderer.BackColor = Color.Empty;
                gdiRenderer.Render(wnd.Document as SvgDocument);

                //wnd.Render();
                image = gdiRenderer.RasterImage;
                image.Save(@"c:\inlinesvg.png", ImageFormat.Png);
            }
            else
            {
                image = iElement.Bitmap;
            }

            if (image != null)
            {
                graphics.DrawImage(this, image, destRect, 0f, 0f, image.Width, image.Height, GraphicsUnit.Pixel, imageAttributes);
            }
            //}
        }
Ejemplo n.º 2
0
        private Image getImage(RectangleF bounds)
        {
            GdiRenderer renderer = new GdiRenderer();
            renderer.Window = _patternElement.OwnerDocument.Window as SvgWindow;

            SvgSvgElement elm = moveIntoSvgElement();

            Image img = renderer.Render(elm as SvgElement);

            moveOutOfSvgElement(elm);

            return img;
        }
Ejemplo n.º 3
0
        private Image getImage(RectangleF bounds)
        {
            GdiRenderer renderer = new GdiRenderer();

            renderer.Window = _patternElement.OwnerDocument.Window as SvgWindow;

            SvgSvgElement elm = moveIntoSvgElement();

            Image img = renderer.Render(elm as SvgElement);

            moveOutOfSvgElement(elm);

            return(img);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// The following code will load the SVGDOM, render to a emf, and
        /// place the EMF on the clipboard. Kt seems more complicated than it should
        /// see http://www.dotnet247.com/247reference/msgs/23/118514.aspx
        /// for why the straight forward solution does not work.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void miCopy_Click(
			object sender,
			System.EventArgs e)
        {
            if (svgUrlCombo.Text.Length > 0)
            {
                int width = 500;
                int height = 500;

                // make SVG document with associated window so we can render it.
                SvgWindow window = new SvgWindow(width, height, null);
                GdiRenderer renderer = new GdiRenderer();
                renderer.Window = window;
                window.Renderer = renderer;
                window.Src = svgUrlCombo.Text;

                // copy and paste code taken from
                // http://www.dotnet247.com/247reference/msgs/23/117611.aspx
                // putting a plain MetaFile on the clipboard does not work.
                // .Net's metafile format is not recognised by most programs.
                Graphics g = CreateGraphics();
                IntPtr hdc = g.GetHdc();
                Metafile m = new Metafile(hdc, EmfType.EmfOnly);
                g.ReleaseHdc(hdc);
                g.Dispose();
                g = Graphics.FromImage(m);

                // draw the SVG here
                // NOTE: the graphics object is automatically Disposed by the
                // GdiRenderer.
                renderer.Graphics = g;
                renderer.Render(window.Document as SvgDocument);
                //window.Render();

                // put meta file on the clipboard.
                IntPtr hwnd = this.Handle;
                if (Win32.OpenClipboard(hwnd))
                {
                    Win32.EmptyClipboard();
                    IntPtr hemf = m.GetHenhmetafile();
                    Win32.SetClipboardData(14, hemf); //CF_ENHMETAFILE=14
                    Win32.CloseClipboard();
                }
            }
        }