ASP.NET图形编程部分示例

ContractedBlock.gif ExpandedBlockStart.gif          Page_Load #region Page_Load
InBlock.gif        
private void Page_Load(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
// 在此处放置用户代码以初始化页面
InBlock.gif
            if(! IsPostBack)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
string _ChartType = "";
InBlock.gif                
if(Request.QueryString["ChartType"!= null && Request.QueryString["ChartType"].Trim().Length > 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    _ChartType 
= Request.QueryString["ChartType"].Trim();
ExpandedSubBlockEnd.gif                }

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

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif        
#endregion

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

ExpandedBlockEnd.gif        
#endregion

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

ExpandedBlockEnd.gif        
#endregion

None.gif
None.gif        
// 画矩形组
ContractedBlock.gifExpandedBlockStart.gif
         ShowRectangles #region ShowRectangles
InBlock.gif        
private void ShowRectangles()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Bitmap _bmImage 
= new Bitmap(300,300);
InBlock.gif            Graphics _ghG 
= Graphics.FromImage( _bmImage );
InBlock.gif            _ghG.Clear( Color.Wheat );
InBlock.gif            Pen _penRed 
= new Pen( Color.Red, 1);
InBlock.gif            
//=====================
InBlock.gif
            Rectangle[] _rect = new Rectangle[5];
InBlock.gif
InBlock.gif            
int _left = 10;
InBlock.gif            
int _width = 10;
InBlock.gif            
int _space = 10;
InBlock.gif            
int _level = 250;
InBlock.gif
InBlock.gif            
forint index = 0; index < _rect.Length; index++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _rect[index] 
= new Rectangle();
InBlock.gif                _rect[index].X 
= _left + index * ( _width + _space);
InBlock.gif                _rect[index].Y 
= _level - 15 * index;
InBlock.gif                _rect[index].Width 
= _width;
InBlock.gif                _rect[index].Height 
=  15 * index;
ExpandedSubBlockEnd.gif            }

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

ExpandedBlockEnd.gif        
#endregion

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

ExpandedBlockEnd.gif        
#endregion

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

ExpandedBlockEnd.gif        
#endregion

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

ExpandedBlockEnd.gif        
#endregion

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

ExpandedBlockEnd.gif        
#endregion

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

ExpandedBlockEnd.gif        
#endregion

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

ExpandedBlockEnd.gif        
#endregion

None.gif
None.gif        
// 填充矩形组
ContractedBlock.gifExpandedBlockStart.gif
         FillRectangles #region FillRectangles
InBlock.gif        
private void FillRectangles()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Bitmap _bmImage 
= new Bitmap(300,300);
InBlock.gif            Graphics _gpG 
= Graphics.FromImage( _bmImage );
InBlock.gif            _gpG.Clear( Color.Wheat );
InBlock.gif            SolidBrush _brush 
= new SolidBrush( Color.Black );
InBlock.gif            
//=======================================
InBlock.gif
            Pen _penRed = new Pen(Color.Red, 5);
InBlock.gif            Rectangle[] _rect 
= new Rectangle[5];
InBlock.gif            
int _left = 10;
InBlock.gif            
int _width = 10;
InBlock.gif            
int _space = 10;
InBlock.gif            
int _level = 250;
InBlock.gif
InBlock.gif            
forint index = 0; index < _rect.Length; index++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                _rect[index] 
= new Rectangle();
InBlock.gif                _rect[index].X 
= _left + index * ( _width + _space);
InBlock.gif                _rect[index].Y 
= _level - 15 * index;
InBlock.gif                _rect[index].Width 
= _width;
InBlock.gif                _rect[index].Height 
=  15 * index;
ExpandedSubBlockEnd.gif            }

InBlock.gif            _gpG.FillRectangles( _brush, _rect);
InBlock.gif
InBlock.gif            _gpG.DrawLine( _penRed,_left,_level,
250,_level);
InBlock.gif
InBlock.gif            
//======================================
InBlock.gif
            _bmImage.Save( Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif );
InBlock.gif            _bmImage.Dispose();
InBlock.gif            _gpG.Dispose();
ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif        
#endregion

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

ExpandedBlockEnd.gif        
#endregion

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

ExpandedBlockEnd.gif        
#endregion

转载于:https://www.cnblogs.com/timsoft/articles/424081.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值