当前位置:首页 > 博客园 >ASP.NET图形编程部分示例

ASP.NET图形编程部分示例

  作者:Tim工作室   来源: 博客园-timsoft  
         Page_Load #region Page_Load
        
private void Page_Load(object sender, System.EventArgs e)
        
{
            
// 在此处放置用户代码以初始化页面
            if(! IsPostBack)
            
{
                
string _ChartType = "";
                
if(Request.QueryString["ChartType"!= null && Request.QueryString["ChartType"].Trim().Length > 0)
                
{
                    _ChartType 
= Request.QueryString["ChartType"].Trim();
                }

                
switch( _ChartType )
                
{
                    
case "Line"://画直线
                        ShowLine();
                        
break;
                    
case "Rectangle"://画矩形
                        ShowRectangle();
                        
break;
                    
case "FRectangle"://填充矩形
                        FillRectangle();
                        
break;
                    
case "Rectangles"://画矩形组
                        ShowRectangles();
                        
break;
                    
case "FRectangles"://填充矩形组
                        FillRectangles();
                        
break;
                    
case "Polygon"://画多边形
                        ShowPolygon();
                        
break;
                    
case "Ellipse"://画椭圆
                        ShowEllipse();
                        
break;
                    
case "FEllipse"://填充椭圆
                        FillEllipse();
                        
break;
                    
case "String"://画文字
                        ShowString();
                        
break;
                    
case "Arc"://画弧形
                        ShowArc();
                        
break;
                    
case "Pie"://画扇形
                        ShowPie();
                        
break;
                    
case "FPie"://填充扇形
                        FillPie();
                        
break;
                    
default:
                        ShowLine();
                        
break;
                }

            }

        }

        
#endregion


        
// 画直线
         ShowLine #region ShowLine
        
private void ShowLine()
        
{
            
//创建Graphics对象
            Bitmap _bmImage = new Bitmap(300,300);
            Graphics _ghG 
= Graphics.FromImage( _bmImage );
            
//清除整个绘图面并以指定背景色填充
            _ghG.Clear( Color.Wheat );
            
//创建画笔
            Pen _penRed = new Pen( Color.Red, 5);
            
//=====================
            
//绘制一条连接由坐标对指定的两个点的线条
            _ghG.DrawLine( _penRed,10,10,200,10 );
            
//==========================
            
//将此图像以指定的格式保存到指定的流中
            _bmImage.Save( Response.OutputStream,System.Drawing.Imaging.ImageFormat.Gif );
            _bmImage.Dispose();
            _ghG.Dispose();
        }

        
#endregion


        
// 画矩形
         ShowRectangle #region ShowRectangle
        
private void ShowRectangle()
        
{
            Bitmap _bmImage 
= new Bitmap(300,300);
            Graphics _ghG 
= Graphics.FromImage( _bmImage );
            _ghG.Clear( Color.Wheat  );
            Pen _penRed 
= new Pen( Color.Red, 5);
            
//=============
            _ghG.DrawRectangle( _penRed, 101020150);
            
//=================
            _bmImage.Save( Response.OutputStream,System.Drawing.Imaging.ImageFormat.Gif );
            _bmImage.Dispose();
            _ghG.Dispose();
        }

        
#endregion


        
// 画矩形组
         ShowRectangles #region ShowRectangles
        
private void ShowRectangles()
        
{
            Bitmap _bmImage 
= new Bitmap(300,300);
            Graphics _ghG 
= Graphics.FromImage( _bmImage );
            _ghG.Clear( Color.Wheat );
            Pen _penRed 
= new Pen( Color.Red, 1);
            
//=====================
            Rectangle[] _rect = new Rectangle[5];

            
int _left = 10;
            
int _width = 10;
            
int _space = 10;
            
int _level = 250;

            
forint index = 0; index < _rect.Length; index++)
            
{
                _rect[index] 
= new Rectangle();
                _rect[index].X 
= _left + index * ( _width + _space);
                _rect[index].Y 
= _level - 15 * index;
                _rect[index].Width 
= _width;
                _rect[index].Height 
=  15 * index;
            }

            _ghG.DrawRectangles( _penRed, _rect);

            _ghG.DrawLine( _penRed,_left,_level,
250,_level);
            
//=====================
            _bmImage.Save( Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif );
            _bmImage.Dispose();
            _ghG.Dispose();
        }

        
#endregion


        
// 画多边形
         ShowPolygon #region ShowPolygon
        
private void ShowPolygon()
        
{
            Bitmap _bmImage 
= new Bitmap(300,300);
            Graphics _ghG 
= Graphics.FromImage( _bmImage );
            _ghG.Clear(  Color.Wheat );
            Pen _penRed 
= new Pen( Color.Red, 5);
            
//========
            Point _p1 = new Point(100,100);
            Point _p2 
= new Point(150,100);
            Point _p3 
= new Point(100,200);
            _ghG.DrawPolygon( _penRed, 
new Point[]{_p1,_p2,_p3} );
            
//==============
            _bmImage.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif );
            _bmImage.Dispose();
            _ghG.Dispose();
        }

        
#endregion


        
// 画椭圆
         ShowEllipse #region ShowEllipse
        
private void ShowEllipse()
        
{
            Bitmap _bmImage 
= new Bitmap(300,300);
            Graphics _gpG 
= Graphics.FromImage( _bmImage );
            _gpG.Clear( Color.Wheat );
            Pen _penRed 
= new Pen( Color.Red, 5);
            
//===================
            _gpG.DrawEllipse( _penRed,10,20,100,75);
            
//====================
            _bmImage.Save( Response.OutputStream,System.Drawing.Imaging.ImageFormat.Gif);
            _bmImage.Dispose();
            _gpG.Dispose();
        }

        
#endregion


        
// 画文字
         ShowString #region ShowString
        
private void ShowString()
        
{
            Bitmap _bmImage 
= new Bitmap(300,300);
            Graphics _gpG 
= Graphics.FromImage( _bmImage );
            _gpG.Clear( Color.Wheat );
            
//===================
            string _String = "Study GDI";
            Font _font 
= new Font("宋体",12F);
            SolidBrush _brush 
= new SolidBrush( Color.Red );
            _gpG.DrawString( _String, _font, _brush, 
20,50);
            
//====================
            _bmImage.Save( Response.OutputStream,System.Drawing.Imaging.ImageFormat.Gif);
            _bmImage.Dispose();
            _gpG.Dispose();
        }

        
#endregion


        
// 画弧形
         ShowArc #region ShowArc
        
private void ShowArc()
        
{
            Bitmap _bmImage 
= new Bitmap(300,300);
            Graphics _gpG 
= Graphics.FromImage( _bmImage );
            _gpG.Clear( Color.Wheat );
            Pen _penRed 
= new Pen(Color.Red, 5);
            
//=================================
            Rectangle _rect = new Rectangle(10,10,150,150);
            _gpG.DrawArc(_penRed, _rect,
0,270);
            
//=================================
            _bmImage.Save( Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif );
            _bmImage.Dispose();
            _gpG.Dispose();
        }

        
#endregion


        
// 画扇形
         ShowPie #region ShowPie
        
private void ShowPie()
        
{
            Bitmap _bmImage 
= new Bitmap(300,300);
            Graphics _gpG 
= Graphics.FromImage( _bmImage );
            _gpG.Clear( Color.Wheat );
            Pen _penRed 
= new Pen(Color.Red, 5);
            
//=================================
            Rectangle _rect = new Rectangle(10,10,150,150);
            _gpG.DrawPie(_penRed, _rect,
0,270);
            
//=================================
            _bmImage.Save( Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif );
            _bmImage.Dispose();
            _gpG.Dispose();
        }

        
#endregion


        
// 填充矩形
         FillRectangle #region FillRectangle
        
private void FillRectangle()
        
{
            Bitmap _bmImage 
= new Bitmap(300,300);
            Graphics _gpG 
= Graphics.FromImage( _bmImage );
            _gpG.Clear( Color.Wheat );
            SolidBrush _brush 
= new SolidBrush( Color.Black );
            
//=======================================
            _gpG.FillRectangle( _brush, 10,10,100,150);
            
//======================================
            _bmImage.Save( Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif );
            _bmImage.Dispose();
            _gpG.Dispose();
        }

        
#endregion


        
// 填充矩形组
         FillRectangles #region FillRectangles
        
private void FillRectangles()
        
{
            Bitmap _bmImage 
= new Bitmap(300,300);
            Graphics _gpG 
= Graphics.FromImage( _bmImage );
            _gpG.Clear( Color.Wheat );
            SolidBrush _brush 
= new SolidBrush( Color.Black );
            
//=======================================
            Pen _penRed = new Pen(Color.Red, 5);
            Rectangle[] _rect 
= new Rectangle[5];
            
int _left = 10;
            
int _width = 10;
            
int _space = 10;
            
int _level = 250;

            
forint index = 0; index < _rect.Length; index++)
            
{
                _rect[index] 
= new Rectangle();
                _rect[index].X 
= _left + index * ( _width + _space);
                _rect[index].Y 
= _level - 15 * index;
                _rect[index].Width 
= _width;
                _rect[index].Height 
=  15 * index;
            }

            _gpG.FillRectangles( _brush, _rect);

            _gpG.DrawLine( _penRed,_left,_level,
250,_level);

            
//======================================
            _bmImage.Save( Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif );
            _bmImage.Dispose();
            _gpG.Dispose();
        }

        
#endregion


        
// 填充椭圆
         FillEllipse #region FillEllipse
        
private void FillEllipse()
        
{
            Bitmap _bmImage 
= new Bitmap(300,300);
            Graphics _gpG 
= Graphics.FromImage( _bmImage );
            _gpG.Clear( Color.Wheat );
            
//===================
            SolidBrush _brush = new SolidBrush( Color.Black );
            _gpG.FillEllipse( _brush,
10,20,100,75);
            
//====================
            _bmImage.Save( Response.OutputStream,System.Drawing.Imaging.ImageFormat.Gif);
            _bmImage.Dispose();
            _gpG.Dispose();
        }

        
#endregion


        
// 填充扇形
         FillPie #region FillPie
        
private void FillPie()
        
{
            Bitmap _bmImage 
= new Bitmap(300,300);
            Graphics _gpG 
= Graphics.FromImage( _bmImage );
            _gpG.Clear( Color.Wheat );
            SolidBrush _brush 
= new SolidBrush( Color.Black );
            
//=================================
            Rectangle _rect = new Rectangle(10,10,150,150);
            _gpG.FillPie(_brush, _rect,
0,270);
            
//=================================
            _bmImage.Save( Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif );
            _bmImage.Dispose();
            _gpG.Dispose();
        }

        
#endregion

相关阅读:

来源:(微信/QQ:420434200,微信公众号:makaidong-com)
       欢迎分享本文,转载请保留出处!

       【原文阅读】:http://www.cnblogs.com/timsoft/articles/424081.html
没有了

  • 评论:
  • 赞助本站

发表一针见血的评论,你还等什么? ◎欢迎参与讨论,我的微信公众号是:makaidong-com
马开东博客赞助