代码改变世界

验证码

2018-04-09 14:01  鹏宝宝  阅读(148)  评论(0)    收藏  举报

public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "image/jpeg";
Random rd = new Random();
int a = rd.Next(1000,10000);
context.Session["yanzenma"] = a;
using (Bitmap bmp = new Bitmap(50, 25))
{
using (Graphics g = Graphics.FromImage(bmp))
using (Font font = new Font(FontFamily.GenericSerif, 15))
{
g.DrawString(a.ToString(), font, Brushes.Red, new PointF(0, 0));
}
bmp.Save(context.Response.OutputStream, ImageFormat.Jpeg);
}
}