<>封装
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
PHP调用shell命令centos7部署springboot jar包一个学生关于鸿蒙系统的一些看法逆向工程核心原理笔记(一)——Hello World-1苹果iPhone 12全系售价泄露:官方最高售价近1万元 疫情过后 学哪个编程有前景抖音比较火的 黑客帝国-代码雨(免费送)error: (-215:Assertion failed)解决方案变量有哪些类型?深入理解指针:一文让你彻底理解指针