<%@ Page Language = "C#" ContentType = "image/jpeg" %> <%@ Import Namespace = "System" %> <%@ Import Namespace = "System.Drawing" %> <%@ Import Namespace = "System.Drawing.Drawing2D" %> <%@ Import Namespace = "System.Drawing.Imaging" %> <html > <head > <script language = "C#" runat = "server" > void Page_Load ( object sender , EventArgs e ) { Bitmap image = new Bitmap ( 400 , 400 ) ; Font axesFont = new Font ( "arial" , 10 ) ; Brush blackBrush = new SolidBrush ( Color . Red ) ; Pen redPen = new Pen ( Color . Red , 1 ) ; Pen blackPen = new Pen ( Color . Blue , 2 ) ; Graphics g = Graphics . FromImage ( image ) ; g . Clear ( Color . White ) ; g . FillRectangle ( new SolidBrush ( Color . LightGreen ) , 0 , 0 , 400 , 400 ) ; //在此图片对象中画出图片,可以定义文字大小、位置、色彩等 g . DrawString ( "在图片上面写入文字,呵呵" , axesFont , blackBrush , 90 , 20 ) ; //以下语句是在此图片对象上画出各种线条,可以定义线条的粗细、起点、终点等 g . DrawLine ( blackPen , 0 , 2 , 210 , 250 ) ; g . DrawLine ( blackPen , 210 , 250 , 310 , 50 ) ; g . DrawLine ( redPen , 310 , 50 , 210 , 350 ) ; //以"Jpeg"格式保存此图片对象,在客户端显示出来 // image . Save ( Response . OutputStream , ImageFormat . Jpeg ) ; image . Save ( Response . OutputStream , ImageFormat . Jpeg ) ; } </script > </head > <body > </body > </html > |