您的当前位置:首页>全部百科>百科问答详情
注:文章内容来源于网络,真实性有待确认,请自行甄别。

验证码源代码实现c#谢谢阿!!

发表于:2024-10-24 00:00:00浏览:3次 分类: 电脑/网络-互联网
问题描述:谢谢阿!!
using ; using System.Web; using System.Drawing; using System.Drawing.Drawing2D; /// /// Summary description for yanzhengma /// public class Yanzhengma { private string GetRandom() { int number; char charCode; string strCode = string.Empty; System.Random random = new System.Random(); for (int i = 1; i <= 5; i++) { number = random.Next(); if (number % 2 == 0) { charCode = (char)('0' + (char)(number % 10)); } else { charCode = (char)('A' + (char)(number % 26)); } strCode += charCode.ToString(); } // System.Web.HttpContext.Current.Response.Cookies HttpContext.Current.Response.Cookies.Add(new HttpCookie("codebycookies", strCode)); return strCode; } public void DrawRandom() { string strCode = GetRandom(); Bitmap image = new Bitmap(100, 30); Graphics huatu = Graphics.FromImage(image); try { //生成随机生成器 Random random = new Random(); //清空图片背景色 huatu.Clear(Color.White); //画图片的背景噪音线 int x1, x2, y1, y2; for (int i = 0; i < 10; i++) { x1 = random.Next(image.Width); x2 = random.Next(image.Width); y1 = random.Next(image.Height); y2 = random.Next(image.Height); huatu.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2); } Font font = new Font("Arial", 20, (FontStyle.Bold | System.Drawing.FontStyle.Italic)); LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.DarkRed, 1.2f, true); huatu.DrawString(strCode, font, brush, 2, 2); //画图片的前景噪音点 for (int i = 0; i < 100; i++) { int x = random.Next(image.Width); int y = random.Next(image.Height); image.SetPixel(x, y, Color.FromArgb(random.Next())); } //画图片的边框线 huatu.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width, image.Height); System.IO.MemoryStream ms = new System.IO.MemoryStream(); image.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); HttpContext.Current.Response.ClearContent(); HttpContext.Current.Response.BinaryWrite(ms.ToArray()); } finally { huatu.Dispose(); image.Dispose(); } } }

猜你喜欢

拍拖的由来
拍拖的由来
发表于:2024-10-24 00:00:00 浏览:105 分类: 电脑/网络-互联网
男朋友生日送什么礼物好呢
男朋友生日送什么礼物好呢
发表于:2024-10-24 00:00:00 浏览:65 分类: 电脑/网络-互联网
新浪网免费邮箱如何申请
新浪网免费邮箱如何申请
发表于:2024-10-24 00:00:00 浏览:61 分类: 电脑/网络-互联网
我只在乎你(歌词)我要歌词
我要词
发表于:2024-10-24 00:00:00 浏览:60 分类: 电脑/网络-互联网
动态ip是什么意思
动态ip是什么意思
发表于:2024-10-24 00:00:00 浏览:59 分类: 电脑/网络-互联网
国家信访局网上投诉受理后查询码在哪里获取
信访局网上投诉 受理后查询码在哪里获取
发表于:2024-10-24 00:00:00 浏览:55 分类: 电脑/网络-互联网
读秀下载方法能详细描述一下读秀下载的方法吗?读秀登录是不是需要帐
能详细描述一下读秀的方法吗?读秀登录是不是需要帐号呀,还是有另的方法 ??
发表于:2024-10-24 00:00:00 浏览:55 分类: 电脑/网络-互联网
百度吧
吧----我的动态里面的记录怎样删除
发表于:2024-10-24 00:00:00 浏览:53 分类: 电脑/网络-互联网
EXCEL图表里如何设置标准线,就是在图表上有一条标准线,用来明?
EXCEL图表里如何设置标准线,就是在图表上有一条标准线,用来明?
发表于:2024-10-24 00:00:00 浏览:50 分类: 电脑/网络-互联网
谁知道skype下载为什么打不开啊?
谁知道ype下载为什么打不开啊?
发表于:2024-10-24 00:00:00 浏览:47 分类: 电脑/网络-互联网