Exemplo n.º 1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="OutputStream"></param>
        /// <param name="Format"></param>
        /// <param name="bShowTransparency">if true, draw squares instead of leaving the
        /// background transparent</param>
        /// <remarks>
        /// bShowTransparency is set to true in design mode, to false otherwise.
        /// </remarks>
        protected MasterPane CreateGraph( System.IO.Stream OutputStream, ImageFormat Format,
				bool bShowTransparency )
        {
            RectangleF rect = new RectangleF( 0, 0, this.Width, this.Height );
            MasterPane mp = new MasterPane( string.Empty, rect );
            mp.Margin.All = 0;
            mp.Fill.IsVisible = false;
            mp.Border.IsVisible = false;

            // create all required panes
            //for ( int i = 0; i < this.PaneCount; i++ )
            //{
            mp.Add( new GraphPane( rect, Title, string.Empty, string.Empty ) );
            //}

            // create output bitmap container
            Bitmap image = new Bitmap( this.Width, this.Height );
            using ( Graphics g = Graphics.FromImage( image ) )
            {
                // Apply layout plan
                //mp.SetLayout( this.PaneLayout );
                mp.ReSize( g, rect );

                // Use callback to gather more settings and data values
                OnDrawPane( g, mp );

                // Allow designer control of axischange
                if ( this.AxisChanged ) mp.AxisChange( g );

                // Render the graph to a bitmap
                if ( bShowTransparency && mp.Fill.Color.A != 255 )
                {
                    //Show the transparency as white/gray filled squares
                    // We need to add the resource namespace to its name
                    //string resourceName = string.Format( "{0}.transparency.png", GetType().Namespace );
                    string resourceName = "ZedGraph.ZedGraph.transparency.png";
                    Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream( resourceName );

                    if ( stream == null )
                        throw new Exception( "Does the Build Action of the resource " + resourceName + " is set to Embedded Resource ?" );

                    using ( System.Drawing.Image brushImage = new Bitmap( stream ) )
                    using ( TextureBrush brush = new TextureBrush( brushImage, WrapMode.Tile ) )
                    {
                        g.FillRectangle( brush, 0, 0, this.Width, this.Height );
                    }
                    stream.Close();
                }
                mp.Draw( g );
            }

            // Stream the graph out
            MemoryStream ms = new MemoryStream();
            image.Save( ms, Format );

            //TODO: provide caching options
            ms.WriteTo( OutputStream );

            return mp;
        }