您当前的位置:中客资源站网络学院.NET专区综合应用 → 文章内容 退出登录 用户管理
本类热门文章
相关下载
c#高性能在WEB端产生验证图片
作者:中客资源  来源:中客资源  发布时间:2007-2-7 2:55:21

减小字体 增大字体

 

using System;
using System.Web;
using System.Drawing ;
 /// <summary>
 /// Png 的摘要说明。
 public sealed class LocalPng:IHttpHandler    
 {
  #region IHttpHandler 成员  
  
  public  void ProcessRequest(HttpContext context)
  {
   if(context.Request["key"]!=null&&context.Request["key"].Length ==4)//还有ACSSI码是1-9的数字和a-z的字母
   {
    string machine_key=context.Request["key"];
    context.Response.Clear(); 
    try
    {  //原图
     Bitmap sImage = new Bitmap(context.Server.MapPath("key.png.bmp"));   //图片路径  
     //验证码图    
     Graphics wg = Graphics.FromImage(sImage);       
     wg.DrawString(machine_key,new Font("Comic Sans MS",14),new SolidBrush(Color.RoyalBlue),3,0);     
     wg.Save();   
     context.Response.ContentType = "image/Jpeg";
     sImage.Save(context.Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);   
     wg.Dispose();   
     sImage.Dispose();   
    }
    catch(Exception e)
    {context.Response.Write(e.Message);
    }
    context.Response.End();
   
   } 
  }

  public bool IsReusable
  {
   get
   {
    // TODO:  添加 CodeKey.IsReusable getter 实现
    return false;
   }
  }

  #endregion
 }


[] [返回上一页] [打 印]
文章评论 (评论内容只代表网友观点,与本站立场无关!)

用户名: 查看更多评论

分 值:100分 85分 70分 55分 40分 25分 10分 0分

内 容:

         (注“”为必填内容。) 验证码: 验证码,看不清楚?请点击刷新验证码