163K网站系统官方论坛's Archiver

longyi 发表于 2007-2-16 18:20

.net教程:c#高性能在web端产生验证图片

[size=3]  
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
}




[/size]

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.