<>封装
public class VerifyCodeHelper { public static Bitmap CreateVerifyCode(out
string code) { //建立Bitmap对象,绘图 Bitmap bitmap = new Bitmap(200, 60); Graphics
graph= Graphics.FromImage(bitmap); graph.FillRectangle(new SolidBrush(Color.
White), 0, 0, 200, 60); Font font = new Font(FontFamily.GenericSerif, 48,
FontStyle.Bold, GraphicsUnit.Pixel); Random r = new Random(); string letters =
"ABCDEFGHIJKLMNPQRSTUVWXYZ0123456789"; StringBuilder sb = new StringBuilder();
//添加随机的五个字母 for (int x = 0; x < 5; x++) { string letter = letters.Substring(r.
Next(0, letters.Length - 1), 1); sb.Append(letter); graph.DrawString(letter,
font, new SolidBrush(Color.Black), x * 38, r.Next(0, 15)); } code = sb.ToString(
); //混淆背景 Pen linePen = new Pen(new SolidBrush(Color.Black), 2); for (int x = 0;
x< 6; x++) graph.DrawLine(linePen, new Point(r.Next(0, 199), r.Next(0, 59)),
new Point(r.Next(0, 199), r.Next(0, 59))); return bitmap; } }
使用
public ActionResult VerifyCode() { string code = ""; Bitmap bitmap =
VerifyCodeHelper.CreateVerifyCode(out code); base.HttpContext.Session.SetString(
"CheckCode", code); MemoryStream stream = new MemoryStream(); bitmap.Save(stream
, ImageFormat.Gif); return File(stream.ToArray(), "image/gif"); }

技术
©2020 ioDraw All rights reserved
哇靠靠,这也行?零基础DIY无人驾驶小车(二)通讯流程图Android 原生项目集成 FlutterPython绘制的爱心树与表白代码你知道Python基础包含哪些内容?学习什么吗?世界上第一个成像探测器运用激光和声音探测癌细胞JWT expired at 2021-03-08T14:02:47+0800. Current time: 2021-03-08T14:03:12+0800Python基于Django学生教务选课系统设计智慧城市发展情况及未来Angular添加自定义属性并绑定一个变量