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

本文介绍了一个用于处理Png图片的类LocalPng,该类实现了IHttpHandler接口,并能根据请求参数生成带有指定文本的JPEG图片。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

导读:
  using System;
  using System.Web;
  using System.Drawing ;
  ///
  /// 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;
  }
  }

本文转自
http://study.qqcf.com/web/224/24038.htm
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值