求助: 验证码字库
诚恳求助如图所示的验证码字库!在一个为孩子的投票网站,大家都在作弊,所以本人也想尝试,可是这个样子的字库在网络上没找到,哪位易做图能帮忙做一个这样的字库!字库的扩展名好象是.dat
--------------------编程问答--------------------
--------------------编程问答--------------------
--------------------编程问答-------------------- 这个可以用GDI+画图来做
这些字库应该都是已经录入好的字吧
然后读这个.DAT文件 随机取几个出来 用GDI+画图,生成验证码图片
我的做法是这样的,不知道还有没有其他办法? --------------------编程问答--------------------
我也查了相关的资料,好象是这个道理,只不过偶有点不会做这个,能不能求会的朋友给做一个这样的.dat文件!
小女子静静在这里期待着.........
--------------------编程问答-------------------- 继续等待中........... --------------------编程问答-------------------- //产生验证码
private string GenerateCheckCode()
{
int number;
char code;
string checkCode = String.Empty;
Random random = new Random();
for (int i = 0; i < 5; i++)
{
number = random.Next();
if (number % 2 == 0)
code = (char)('0' + (char)(number % 10));
else
code = (char)('A' + (char)(number % 26));
checkCode += code.ToString();
}
Session["ValidateCode"] = checkCode;
return checkCode;
}
//产生验证图片
private void CreateCheckCodeImage(string checkCode)
{
if (checkCode == null || checkCode.Trim() == String.Empty)
{
return;
}
System.Drawing.Bitmap image = new System.Drawing.Bitmap((int)Math.Ceiling((checkCode.Length * 12.5)), 22);
Graphics g = Graphics.FromImage(image);
try
{
//生成随机生成器
Random random = new Random();
//清空图片背景色
g.Clear(Color.White);
//画图片的背景噪音线
for (int i = 0; i < 25; i++)
{
int x1 = random.Next(image.Width);
int x2 = random.Next(image.Width);
int y1 = random.Next(image.Height);
int y2 = random.Next(image.Height);
g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2);
}
Font font = new System.Drawing.Font("Arial", 12, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic));
System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.DarkRed, 1.2f, true);
g.DrawString(checkCode, 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()));
}
//画图片的边框线
g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
Response.ClearContent();
Response.ContentType = "image/Gif";
Response.BinaryWrite(ms.ToArray());
}
finally
{
g.Dispose();
image.Dispose();
}
} --------------------编程问答--------------------
--------------------编程问答-------------------- 楼上两位朋友,能不能再给小女子生成一个.dat文件,嘿嘿,偶太笨,不会生成文件!
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
public partial class Admin_Image : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Random Rnd = new Random();
string mystr = Rnd.Next(1000, 9999).ToString();
Session["imageNum"] = mystr;
Bitmap bit = new Bitmap(50, 20);
Graphics g = Graphics.FromImage(bit);
g.Clear(Color.SeaShell);
Font f = new System.Drawing.Font("Arial", 14, System.Drawing.FontStyle.Regular);
Brush b = System.Drawing.Brushes.Black;
g.DrawString(mystr, f, b, 0, 0);
MemoryStream M = new MemoryStream();
bit.Save(M, ImageFormat.Jpeg);
Response.BinaryWrite(M.ToArray());
M.Dispose();
bit.Dispose();
g.Dispose();
}
}
先鞠躬90度,谢谢两位朋友!! --------------------编程问答-------------------- 汗~~~这帖零分啊
补充:.NET技术 , ASP.NET