Пример #1
0
        /// <summary>
        /// Gets an enhanced metafile image for the current GraphPane.
        /// </summary>
        /// <seealso cref="GetImage()"/>
        /// <seealso cref="GetImage(int,int,float)"/>
        /// <seealso cref="GetMetafile(int,int)"/>
        public Metafile GetMetafile()
        {
            Bitmap bm = new Bitmap( 1, 1 );
            using ( Graphics g = Graphics.FromImage( bm ) )
            {
                IntPtr hdc = g.GetHdc();
                Stream stream = new MemoryStream();
                Metafile metafile = new Metafile( stream, hdc, _rect,
                            MetafileFrameUnit.Pixel, EmfType.EmfOnly );

                using (IGraphics metafileGraphics = new GdiGraphics(Graphics.FromImage(metafile)))
                {
                    metafileGraphics.TranslateTransform( -_rect.Left, -_rect.Top );
                    metafileGraphics.PageUnit = GraphicsUnit.Pixel;
                    PointF P = new PointF( _rect.Width, _rect.Height );
                    PointF[] PA = new[] { P };
                    metafileGraphics.TransformPoints( CoordinateSpace.Page, CoordinateSpace.Device, PA );
                    //metafileGraphics.PageScale = 1f;

                    // output
                    Draw( metafileGraphics );

                    g.ReleaseHdc( hdc );
                    return metafile;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Gets an enhanced metafile image for the current GraphPane, scaled to the specified size.
        /// </summary>
        /// <remarks>
        /// By definition, a Metafile is a vector drawing, and therefore scaling should not matter.
        /// However, this method is provided because certain options in Zedgraph, such as
        /// <see cref="IsFontsScaled" /> are affected by the size of the expected image.
        /// </remarks>
        /// <param name="width">The "effective" scaled width of the bitmap in pixels</param>
        /// <param name="height">The "effective" scaled height of the bitmap in pixels</param>
        /// <param name="isAntiAlias">true to use anti-aliased drawing mode, false otherwise</param>
        /// <seealso cref="GetImage()"/>
        /// <seealso cref="GetImage(int,int,float)"/>
        /// <seealso cref="GetMetafile()"/>
        public Metafile GetMetafile( int width, int height, bool isAntiAlias )
        {
            Bitmap bm = new Bitmap( 1, 1 );
            using ( Graphics g = Graphics.FromImage( bm ) )
            {
                IntPtr hdc = g.GetHdc();
                Stream stream = new MemoryStream();
                Metafile metafile = new Metafile( stream, hdc, _rect,
                            MetafileFrameUnit.Pixel, EmfType.EmfPlusDual );
                g.ReleaseHdc( hdc );

                using (IGraphics metafileGraphics = new GdiGraphics(Graphics.FromImage(metafile)))
                {
                    //metafileGraphics.TranslateTransform( -_rect.Left, -_rect.Top );
                    metafileGraphics.PageUnit = System.Drawing.GraphicsUnit.Pixel;
                    PointF P = new PointF( width, height );
                    PointF[] PA = new PointF[] { P };
                    metafileGraphics.TransformPoints( CoordinateSpace.Page, CoordinateSpace.Device, PA );
                    //metafileGraphics.PageScale = 1f;

                    // output
                    MakeImage( metafileGraphics, width, height, isAntiAlias );
                    //this.Draw( metafileGraphics );

                    return metafile;
                }
            }
        }