Admin/yzmhandle.ashx.cs
(完整代码) 2KBusing System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
//需要在这里画一个图片,添加画图类的引用
using System.Drawing;
//因为验证码生成后,我们需要找个容器保存
//这个验证码图片中的数字,我们使用内置对象
//session来保存在会话期间跨页信息传递P105
//读取该值需要实现一个接口,来获取httpsessionstate
//对象
namespace mybook.Admin
{
/// <summary>
/// yzmhandle 的摘要说明
/// </summary>
public class yzmhandle : IHttpHandler,System.Web.SessionState .IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/jpeg";
//生成验证码图片
using(Bitmap bm=new Bitmap (30,20))//图片
{
//向图片画内容
using(Graphics g=Graphics .FromImage (bm))
{
//画一个矩形,底色为灰色
g.FillRectangle(new SolidBrush(Color.Gray), new Rectangle(0, 0, bm.Width, bm.Height));
//生成图片中的随机数
Random rand = new Random();
int code = rand.Next(1000, 9999);
string strcode = code.ToString();
//将这个数字以字符串保存到session中
HttpContext.Current.Session["code"] = strcode;
//把随机数画到图中
g.DrawString(strcode, new Font("宋体", 10), Brushes.Black, new PointF(0, 0));
g.DrawEllipse(Pens.Red, new Rectangle(10, 10, 10, 10));
g.DrawLine(Pens.Green, new PointF(0, 0), new PointF(30, 30));
//把画好的图片保存输出
bm.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。
