网站开发验证码后台生成代码 不同颜色的文字背景
合集下载
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
//定义字体样式
//Chiller
Font font = new Font(new FontFamily("Georgia"), 18, FontStyle.Bold, GraphicsUnit.Pixel);
//绘制随机数
letter = letters.Substring(r.Next(0, letters.Length - 1), 1);
s.Append(letter);
//Color C1 = GetRandomColor();
//}
//将图片保存到输出流中
bitmap.Save(context.Response.OutputStream, ImageFormat.Gif);
//如果没有实现IRequiresSessionState,则这里会出错,也无法生成图片
System.Threading.Thread.Sleep(10);
int int_Blue = R.Next(0, 255);
return Color.FromArgb(int_Red, int_Green, int_Blue);
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Drawing;
using System.Text;
using System.Drawing.Imaging;
StringBuilder s = new StringBuilder();
//生成组员随即验证码
//添加随机的五个字母
for (int x = 0; x < 4; x++)
{
// 为了在白色背景上显示,尽量生成深色
int int_Red = R.Next(0, 255);
System.Threading.Thread.Sleep(10);
int int_Green = R.Next(0, 255);
context.Session["code"] = s.ToString();
context.Response.End();
}
public Color GetRandomColor()
{
Random R = new Random();
int width = 60;
int height = 21;
Bitmap bitmap = new Bitmap(width, height);
//创建绘图类
Graphics g = Graphics.FromImage(bitmap);
Random r = new Random();
string letters = "QWERTYUIOPASDFGHJKLZXCVBNM1234567890";
//生成的字母
string letter;
}
public bool IsReusable
{
{
return false;
}
}
}
}
using System.Web.SessionState;
namespace HRMS.WebUI.HttpHandler
{
/// <summary>
/// ValidateCode 的摘要说明
/// </summary>
public class ValidateCode : IHttpHandler, IRequiresSessionState
//}
g.DrawString(letter, font, new SolidBrush(GetRandomColor()), x * 15, r.Next(-3, 3));
}
//添加干扰线
Pen p = new Pen(new SolidBrush(Color.Red), 1);
//for (int x = 0; x < 4; x++)
//{
// g.DrawLine(p, new Point(r.Next(0, width), r.Next(0, height)), new Point(r.Next(0, width), r.Next(0, height)));
//绘制图形(SolidBrush SolidBrush 定义单色画刷。画刷用于填充图形形状)
Color C = GetRandomColor();
g.FillRectangle(new SolidBrush(C), 0, 0, width, height);
//if (C == C1)
//{
// C1 = GetRandomColor();
//}
//else
//{
{
public void ProcessRequest(HttpContext context)
{
//响应类型
context.Response.ContentType = "image/jpg";
//建立画板(设置画板大小)
//Chiller
Font font = new Font(new FontFamily("Georgia"), 18, FontStyle.Bold, GraphicsUnit.Pixel);
//绘制随机数
letter = letters.Substring(r.Next(0, letters.Length - 1), 1);
s.Append(letter);
//Color C1 = GetRandomColor();
//}
//将图片保存到输出流中
bitmap.Save(context.Response.OutputStream, ImageFormat.Gif);
//如果没有实现IRequiresSessionState,则这里会出错,也无法生成图片
System.Threading.Thread.Sleep(10);
int int_Blue = R.Next(0, 255);
return Color.FromArgb(int_Red, int_Green, int_Blue);
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Drawing;
using System.Text;
using System.Drawing.Imaging;
StringBuilder s = new StringBuilder();
//生成组员随即验证码
//添加随机的五个字母
for (int x = 0; x < 4; x++)
{
// 为了在白色背景上显示,尽量生成深色
int int_Red = R.Next(0, 255);
System.Threading.Thread.Sleep(10);
int int_Green = R.Next(0, 255);
context.Session["code"] = s.ToString();
context.Response.End();
}
public Color GetRandomColor()
{
Random R = new Random();
int width = 60;
int height = 21;
Bitmap bitmap = new Bitmap(width, height);
//创建绘图类
Graphics g = Graphics.FromImage(bitmap);
Random r = new Random();
string letters = "QWERTYUIOPASDFGHJKLZXCVBNM1234567890";
//生成的字母
string letter;
}
public bool IsReusable
{
{
return false;
}
}
}
}
using System.Web.SessionState;
namespace HRMS.WebUI.HttpHandler
{
/// <summary>
/// ValidateCode 的摘要说明
/// </summary>
public class ValidateCode : IHttpHandler, IRequiresSessionState
//}
g.DrawString(letter, font, new SolidBrush(GetRandomColor()), x * 15, r.Next(-3, 3));
}
//添加干扰线
Pen p = new Pen(new SolidBrush(Color.Red), 1);
//for (int x = 0; x < 4; x++)
//{
// g.DrawLine(p, new Point(r.Next(0, width), r.Next(0, height)), new Point(r.Next(0, width), r.Next(0, height)));
//绘制图形(SolidBrush SolidBrush 定义单色画刷。画刷用于填充图形形状)
Color C = GetRandomColor();
g.FillRectangle(new SolidBrush(C), 0, 0, width, height);
//if (C == C1)
//{
// C1 = GetRandomColor();
//}
//else
//{
{
public void ProcessRequest(HttpContext context)
{
//响应类型
context.Response.ContentType = "image/jpg";
//建立画板(设置画板大小)