全部分求一段代码,验证码识别 如题识别验证码图片有数字,有字母有点粘有示例图片需要的qq100291677 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 新建一个页面放生成验证码的验证码.sapxprotected void Page_Load(object sender, EventArgs e) { System.Random rand = new Random(); int len = rand.Next(4, 6); char[] chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray(); System.Text.StringBuilder myStr = new System.Text.StringBuilder(); for (int iCount = 0; iCount < len; iCount++) { myStr.Append(chars[rand.Next(chars.Length)]); } string text = myStr.ToString(); // 保存验证码到 session 中以便其他模块使用 this.Session["checkcode"] = text; Size ImageSize = Size.Empty; Font myFont = new Font("MS Sans Serif", 14); // 计算验证码图片大小 using (Bitmap bmp = new Bitmap(10, 10)) { using (Graphics g = Graphics.FromImage(bmp)) { SizeF size = g.MeasureString(text, myFont, 10000); ImageSize.Width = (int)size.Width + 8; ImageSize.Height = (int)size.Height + 8; } } // 创建验证码图片 using (Bitmap bmp = new Bitmap(ImageSize.Width, ImageSize.Height)) { // 绘制验证码文本 using (Graphics g = Graphics.FromImage(bmp)) { g.Clear(Color.White); using (StringFormat f = new StringFormat()) { f.Alignment = StringAlignment.Near; f.LineAlignment = StringAlignment.Center; f.FormatFlags = StringFormatFlags.NoWrap; g.DrawString( text, myFont, Brushes.Black, new RectangleF( 0, 0, ImageSize.Width, ImageSize.Height), f); }//using }//using // 制造噪声 杂点面积占图片面积的 30% int num = ImageSize.Width * ImageSize.Height * 30 / 100; for (int iCount = 0; iCount < num; iCount++) { // 在随机的位置使用随机的颜色设置图片的像素 int x = rand.Next(ImageSize.Width); int y = rand.Next(ImageSize.Height); int r = rand.Next(255); int g = rand.Next(255); int b = rand.Next(255); Color c = Color.FromArgb(r, g, b); bmp.SetPixel(x, y, c); }//for // 输出图片 System.IO.MemoryStream ms = new System.IO.MemoryStream(); bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png); this.Response.ContentType = "image/png"; ms.WriteTo(this.Response.OutputStream); ms.Close(); }//using myFont.Dispose(); }ImageButton1.ImageUrl = "验证码.aspx";if (CheckCode(txtYzm.Text) == false) { Response.Write("<script>alert('请输入正确的验证码!');window.location.href ='UserLogin.aspx'</script>"); }试试可以用的 请问如何制作office软件的演示软件啊 为什么.net2.0的项目加载的时候却需要3.5? Discuz注册接口有人知道没怎么写弄 问一个没多大营养的问题--datatable winform 上传图片预览的问题 关于.net图片上写字的问题 C# using 怎么不起作用? 請問有那位大蝦有 .net 2005 加態生成水晶報表的源碼借來用一用 Asp.Net(c#)中调用c/c++ 编写的Dll的 问题 c#如何实现在一个panel中插入多个picture 请问this加在方法形参的前面做修饰是什么意思 app.config可以自己定义xml元素吗?为何我的编译时给出了消息提示
验证码.sapxprotected void Page_Load(object sender, EventArgs e)
{
System.Random rand = new Random();
int len = rand.Next(4, 6);
char[] chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
System.Text.StringBuilder myStr = new System.Text.StringBuilder();
for (int iCount = 0; iCount < len; iCount++)
{
myStr.Append(chars[rand.Next(chars.Length)]);
}
string text = myStr.ToString();
// 保存验证码到 session 中以便其他模块使用
this.Session["checkcode"] = text;
Size ImageSize = Size.Empty;
Font myFont = new Font("MS Sans Serif", 14);
// 计算验证码图片大小
using (Bitmap bmp = new Bitmap(10, 10))
{
using (Graphics g = Graphics.FromImage(bmp))
{
SizeF size = g.MeasureString(text, myFont, 10000);
ImageSize.Width = (int)size.Width + 8;
ImageSize.Height = (int)size.Height + 8;
}
}
// 创建验证码图片
using (Bitmap bmp = new Bitmap(ImageSize.Width, ImageSize.Height))
{
// 绘制验证码文本
using (Graphics g = Graphics.FromImage(bmp))
{
g.Clear(Color.White);
using (StringFormat f = new StringFormat())
{
f.Alignment = StringAlignment.Near;
f.LineAlignment = StringAlignment.Center;
f.FormatFlags = StringFormatFlags.NoWrap;
g.DrawString(
text,
myFont,
Brushes.Black,
new RectangleF(
0,
0,
ImageSize.Width,
ImageSize.Height),
f);
}//using
}//using
// 制造噪声 杂点面积占图片面积的 30%
int num = ImageSize.Width * ImageSize.Height * 30 / 100;
for (int iCount = 0; iCount < num; iCount++)
{
// 在随机的位置使用随机的颜色设置图片的像素
int x = rand.Next(ImageSize.Width);
int y = rand.Next(ImageSize.Height);
int r = rand.Next(255);
int g = rand.Next(255);
int b = rand.Next(255);
Color c = Color.FromArgb(r, g, b);
bmp.SetPixel(x, y, c);
}//for
// 输出图片
System.IO.MemoryStream ms = new System.IO.MemoryStream();
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
this.Response.ContentType = "image/png";
ms.WriteTo(this.Response.OutputStream);
ms.Close();
}//using
myFont.Dispose(); }ImageButton1.ImageUrl = "验证码.aspx";
if (CheckCode(txtYzm.Text) == false)
{
Response.Write("<script>alert('请输入正确的验证码!');window.location.href ='UserLogin.aspx'</script>");
}
试试可以用的