方法一:將自動產生的圖片儲存在網站的某個位置,然後在頁面的Page_Load中將圖片控制項的scr設為圖片的URL就可以了(此方法的代碼參照http://www.cnblogs.com/ahuang1118/archive/2005/05/27/163614.html)
方法二:將頁面Webform1中的圖片控制項的scr設為另一個專門自動產生圖片的頁面GenPicture的URL。見DEMOusing System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Drawing.Drawing2D;
namespace WebPageIndex
{
/**//// <summary>
/// GenPicture 的摘要說明。
/// </summary>
public class GenPicture : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// 在此處放置使用者代碼以初始化頁面
string str="興中公司財務章";
Bitmap image=new Bitmap(300,300);
Graphics g=Graphics.FromImage(image);
Pen p=new Pen(Brushes.Red,10);
Pen p1=new Pen(Brushes.Red,5);
SolidBrush b=new SolidBrush(Color.Red);
g.SmoothingMode=SmoothingMode.AntiAlias;
Point point1 = new Point( 150, 50);
Point point2 = new Point(50, 150);
Point point3 = new Point(230, 150);
Point[] curvePoints ={point1,point2,point3};
g.FillPolygon(b,curvePoints,FillMode.Winding );
g.DrawEllipse(p,10,10,280,280);
g.DrawString(str,new Font("隸書",20,FontStyle.Bold),new
SolidBrush(Color.FromArgb(255, 255,0, 0)),40,200);
g.DrawLine(p1,80,240,220,240);
g.DrawLine(p1,80,250,220,250);
image.Save(Response.OutputStream,System.Drawing.Imaging.ImageFormat.Gif);
}
Web 表單設計器產生的程式碼#region Web 表單設計器產生的程式碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 該調用是 ASP.NET Web 表單設計器所必需的。
//
InitializeComponent();
base.OnInit(e);
}