c#高性能在WEB端产生验证图片

using System;
using System.Web;
using System.Drawing ;
///

 1<summary>   
 2/// Png 的摘要说明。   
 3public sealed class LocalPng:IHttpHandler   
 4{   
 5#region IHttpHandler 成员   
 6  
 7public void ProcessRequest(HttpContext context)   
 8{   
 9if(context.Request["key"]!=null&amp;&amp;context.Request["key"].Length ==4)//还有ACSSI码是1-9的数字和a-z的字母   
10{   
11string machine_key=context.Request["key"];   
12context.Response.Clear();   
13try   
14{ //原图   
15Bitmap sImage = new Bitmap(context.Server.MapPath("key.png.bmp")); //图片路径   
16//验证码图   
17Graphics wg = Graphics.FromImage(sImage);   
18wg.DrawString(machine_key,new Font("Comic Sans MS",14),new SolidBrush(Color.RoyalBlue),3,0);   
19wg.Save();   
20context.Response.ContentType = "image/Jpeg";   
21sImage.Save(context.Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);   
22wg.Dispose();   
23sImage.Dispose();   
24}   
25catch(Exception e)   
26{context.Response.Write(e.Message);   
27}   
28context.Response.End();   
29  
30}   
31} 
32
33public bool IsReusable   
34{   
35get   
36{   
37// TODO: 添加 CodeKey.IsReusable getter 实现   
38return false;   
39}   
40} 
41
42#endregion   
43} 
44
45![](http://blog.csdn.net/images/blog_csdn_net/skyroles/zbq.aspx)</summary>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus