Bitmap,Graphics,Random等的使用!
Response.Clear();
Response.ContentType = "image/jpeg";
int width = 50;
int height = 25;
Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);
Graphics g = Graphics.FromImage(bmp);
HatchBrush b = new HatchBrush(HatchStyle.Cross, Color.LightGray, Color.WhiteSmoke);
g.FillRectangle(b, 0, 0, width, height);
Random r = new Random(Convert.ToInt32(DateTime.Now.Millisecond));
string Code = r.Next(1000, 9999).ToString();
Session["ValidateCode"] = Code;
g.DrawString(Code, new Font("Arial", 10, FontStyle.Bold), SystemBrushes.WindowText, 10.0F, 5.0F);
bmp.Save(Response.OutputStream, ImageFormat.Jpeg);
b.Dispose();
g.Dispose();
bmp.Dispose();
Response.End();