net验证码源码
‘壹’ .net短信验证码是如何实现的
首先你要有短信的接口,这个你只闭桐有想办法从别的地方购买。
然后:
你先放一个文本框一个按钮填写手机号码庆芹发送短信,然后搞一个临时的库保存下数据,保存手机号码和随机验证码、状态,时间写上5分钟后的时间。这四个参数!
进入等等输入页面,5分钟验证码过期,用过的修改状态誉态毕,5分钟后可以重发。
验证码就这样操作,如果有什么困难的地方可以HI网络我~~~
‘贰’ c# .net 生成图片验证码的代码
说明:
.net 万岁
.net framework 的类库真是太强了, 用 GDI+ 可以干N多N多事情。
广告时间:
shawl.qiu C# CMS 系统 预计40天后开始编码, 现在逐步设计中, 免得到时求职说什么什么作品唉。
PS: 今天求职真是惨不忍睹亏亮正, 谁要招网键缓页相关的请联系 13435580019, 邱先生。
什么地方俺都去, 工资只要能过活就行, 但是食宿问题得解决。
shawl.qiu
2007-02-01
class checkcode:
复制代码 代码如下:
%@ Page Language="C#" AutoEventWireup="True" %
%@ import Namespace="System.Drawing"%
%@ import Namespace="System.Drawing.Drawing2D"%
%@ import Namespace="System.Web"%
script runat="server"
private void Page_Load(object sender, System.EventArgs e)
{
String sRndStr=checkcode.rndStr(4);
checkcode.general(sRndStr);
}
/*-----------------------------------------------------------------------------------*
* shawl.qiu c# .net checkcode class v1.0
*-----------------------------------------------------------------------------------*/
//---------------------------------------------------------------------begin class checkcode
public class checkcode
{
//-----------------------------------begin event
public checkcode()
{
}
~checkcode()
{
}
//-----------------------------------end event
//-----------------------------------begin public constant
//-----------------------begin about
public const String auSubject="shawl.qiu c# .net checkcode class";
public const String auVersion="v1.0";
public const String au="shawl.qiu";
public const String auEmail="[email protected]";
public const String auBlog="";
public const String auCreateDate="2007-2-1";
//-----------------------end about
//-----------------------------------end public constant
//-----------------------------------begin public static method
public static void general(销悔String sCc)
{
Int32 ccLen=sCc.Length;
String ccFtFm="Arial";
Int32 ccFtSz=12;
Int32 ccWidth=ccLen*ccFtSz+1;
Int32 ccHeight=ccFtSz+5;
using(Bitmap oImg = new Bitmap(ccWidth, ccHeight))
{
using(Graphics oGpc=Graphics.FromImage(oImg))
{
HatchBrush hBrush = new HatchBrush(HatchStyle.DashedVertical,
Color.Yellow, Color.Silver);
oGpc.FillRectangle(hBrush, 0, 0, ccWidth, ccWidth);
oGpc.DrawString(sCc,new System.Drawing.Font(ccFtFm,ccFtSz, FontStyle.Bold),
new System.Drawing.SolidBrush(Color.Black),0,0);
//-----------------------边框
Pen blackPen = new Pen(Color.Black, 1);
oGpc.DrawLine(blackPen, 0, ccHeight, 0, 0); // 左竖线
oGpc.DrawLine(blackPen, 0,0,ccWidth,0); // 顶横线
oGpc.DrawLine(blackPen, ccWidth-1,0,ccWidth-1,20); // 右竖线
oGpc.DrawLine(blackPen, 0, ccHeight-1, ccWidth, ccHeight-1); // 底横线
writeImg(oImg);
}
}
} // end public static void general
public static String rndStr(Int32 len)
{
String sTemp="";
String sForRnd="0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
String[] aRnd=sForRnd.Split(',');
Random oRnd=new Random();
Int32 iArLen=aRnd.Length;
for(Int32 i=0; ilen; i++)
{
sTemp+=aRnd[oRnd.Next(0,iArLen)];
}
return sTemp;
} // end public static String rndStr
//-----------------------------------end public static method
//-----------------------------------begin private static method
private static void writeImg(Bitmap oImg)
{
using(System.IO.MemoryStream ms=new System.IO.MemoryStream())
{
oImg.Save(ms,System.Drawing.Imaging.ImageFormat.Png);
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ContentType="image/Png";
HttpContext.Current.Response.BinaryWrite(ms.ToArray());
}
} // end private static void writeImg
}
//---------------------------------------------------------------------end class checkcode
/script
‘叁’ asp.Net的验证码代码怎么写啊
主要代码如下:
//
生成随散轮郑机数字字符串
public
string
GetRandomNumberString(int
int_NumberLength)
{
string
str_Number
=
string.Empty;
Random
theRandomNumber
=
new
Random();
for
(int
int_index
=
0;
int_index
<
int_NumberLength;
int_index++)
str_Number
+=
theRandomNumber.Next(10).ToString();
return
str_Number;
}
生成随机颜色
public
Color
GetRandomColor()
{
Random
RandomNum_First
=
new
Random((int)DateTime.Now.Ticks);
//
对于C#的随机数,没什么好桐穗说的
System.Threading.Thread.Sleep(RandomNum_First.Next(50));
Random
RandomNum_Sencond
=
new
Random((int)DateTime.Now.Ticks);
//
为了在白色背景上显示,尽量生成深色
int
int_Red
=
RandomNum_First.Next(256);
int
int_Green
=
RandomNum_Sencond.Next(256);
int
int_Blue
=
(int_Red
+
int_Green
>
400)
?
0
:
400
-
int_Red
-
int_Green;
int_Blue
=
(int_Blue
>
255)
?
255
:
int_Blue;
return
Color.FromArgb(int_Red,
int_Green,
int_Blue);
}
根据验证字符串生成最终图象
public
void
CreateImage(string
str_ValidateCode)
{
int
int_ImageWidth
=
str_ValidateCode.Length
*
13;
Random
newRandom
=
new
Random();
//
图高20px
Bitmap
theBitmap
=
new
Bitmap(int_ImageWidth,
20);
Graphics
theGraphics
=
Graphics.FromImage(theBitmap);
//
白色背景
theGraphics.Clear(Color.White);
//
灰色边框
theGraphics.DrawRectangle(new
Pen(Color.LightGray,
1),
0,
0,
int_ImageWidth
-
1,
19);
//
10pt的字体
Font
theFont
=
new
Font("Arial",
10);
for
(int
int_index
=
0;
int_index
<
str_ValidateCode.Length;
int_index++)
{
string
str_char
=
str_ValidateCode.Substring(int_index,
1);
Brush
newBrush
=
new
SolidBrush(GetRandomColor());
Point
thePos
=
new
Point(int_index
*
13
+
1
+
newRandom.Next(3),
1
+
newRandom.Next(3));
theGraphics.DrawString(str_char,
theFont,
newBrush,
thePos);
}
//
将生成的图片发回客户冲颂端
MemoryStream
ms
=
new
MemoryStream();
theBitmap.Save(ms,
ImageFormat.Png);
Response.ClearContent();
//需要输出图象信息
要修改HTTP头
Response.ContentType
=
"image/Png";
Response.BinaryWrite(ms.ToArray());
theGraphics.Dispose();
theBitmap.Dispose();
Response.End();
}
最后在Page_Load中调用以上代码
private
void
Page_Load(object
sender,
System.EventArgs
e)
{
if(!IsPostBack)
{
//
4位数字的验证码
string
str_ValidateCode
=
GetRandomNumberString(4);
//
用于验证的Session
Session["ValidateCode"]
=
str_ValidateCode;
CreateImage(str_ValidateCode);
}
}
使用的时候在页面中加入一个Image,将图片路径改为ValidateCode.aspx的相对路径即可
<img
src="ValidateCode.aspx"
/>在需要验证的地方填入如下代码:
if
(TextBox1.Text
==
Session["ValidateCode"].ToString())
{
TextBox1.Text
=
"正确!";
}
else
TextBox1.Text
=
"错误!";OK,基本搞定,总结一下:
‘肆’ c#.net编写一个验证码,点击验证码图片可以切换验证码,输入正确或者错误的时候都有文字提示
两个页面:
1.ValidateCode用于生返简成验证图片的
2.ValidateFormPage表单显示的
ValidateCode.aspx文件不用写代码
ValidateCode.aspx.cs代码如下:
using System;
using System.Drawing;
using System.IO;
using System.Drawing.Imaging;
namespace WebFormDemo
{
public partial class ValidateCode : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// 4位数字的验证码
string str_ValidateCode = GetRandomNumberString(4);
// 用于验证的Session
Session["ValidateCode"] = str_ValidateCode;
CreateImage(str_ValidateCode);
}
}
public string GetRandomNumberString(int int_NumberLength)
{
string str_Number = string.Empty;
Random theRandomNumber = new Random();
for (int int_index = 0; int_index < int_NumberLength; int_index++)
str_Number += theRandomNumber.Next(10).ToString();
return str_Number;
}
//生成随机颜色
public Color GetRandomColor()
{
Random RandomNum_First = new Random((int)DateTime.Now.Ticks);
//前世链 对于C#的随机数,没什么好说的
System.Threading.Thread.Sleep(RandomNum_First.Next(50));
Random RandomNum_Sencond = new Random((int)DateTime.Now.Ticks);
// 为了在白色背景上显示,尽量生成深色
int int_Red = RandomNum_First.Next(256);
int int_Green = RandomNum_Sencond.Next(256);
int int_Blue = (int_Red + int_Green > 400) ? 0 : 400 - int_Red - int_Green;
int_Blue = (int_Blue > 255) ? 255 : int_Blue;
return Color.FromArgb(int_Red, int_Green, int_Blue);
}
//根据验慧孙证字符串生成最终图象
public void CreateImage(string str_ValidateCode)
{
int int_ImageWidth = str_ValidateCode.Length * 13;
Random newRandom = new Random();
// 图高20px
Bitmap theBitmap = new Bitmap(int_ImageWidth, 20);
Graphics theGraphics = Graphics.FromImage(theBitmap);
// 白色背景
theGraphics.Clear(Color.White);
// 灰色边框
theGraphics.DrawRectangle(new Pen(Color.LightGray, 1), 0, 0, int_ImageWidth - 1, 19);
// 10pt的字体
Font theFont = new Font("Arial", 10);
for (int int_index = 0; int_index < str_ValidateCode.Length; int_index++)
{
string str_char = str_ValidateCode.Substring(int_index, 1);
Brush newBrush = new SolidBrush(GetRandomColor());
Point thePos = new Point(int_index * 13 + 1 + newRandom.Next(3), 1 + newRandom.Next(3));
theGraphics.DrawString(str_char, theFont, newBrush, thePos);
}
// 将生成的图片发回客户端
MemoryStream ms = new MemoryStream();
theBitmap.Save(ms, ImageFormat.Png);
Response.ClearContent(); //需要输出图象信息 要修改HTTP头
Response.ContentType = "image/Png";
Response.BinaryWrite(ms.ToArray());
theGraphics.Dispose();
theBitmap.Dispose();
Response.End();
}
}
}
----------------------------------------------------------------------------
ValidateFormPage.aspx文件代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ValidateFormPage.aspx.cs" Inherits="WebFormDemo.ValidateFormPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<img src="ValidateCode.aspx" /><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Label
ID="Label1" runat="server"></asp:Label>
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="验证" />
</div>
</form>
</body>
</html>
----------------------------------------------------------------------------
ValidateFormPage.aspx.cs文件代码如下:
using System;
namespace WebFormDemo
{
public partial class ValidateFormPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
//给按钮加一个点击事件
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text == Session["ValidateCode"].ToString())
{
Label1.Text = "正确!";
}
else
{
Label1.Text = "错误!";
}
}
}
}
‘伍’ asp.net刷新验证码
你这中写法,似乎无法直接刷新
<asp:TextBox ID="txtyzm" runat="server"></asp:TextBox><span class="right"><img src="Yzm.aspx" alt="看不清楚,换一张?首首唯" style="cursor: pointer;" onclick="this.src=this.src+'?'" /></span>
这样的写,是肯定能刷新的芹派
若还有问题也可以私信我哦~
如果满意请【采纳】【赞同】~
最后希望你能够及时采纳,谢谢~
即使不采纳也请赞同下哈~
鼓励下咱,让咱有继续回答问题的动力哈者培~
‘陆’ net mvc 验证码怎么实现
首先你要写一个验证码的Controller,这里我给你粘一个:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Drawing;
usingSystem.Drawing.Imaging;
usingSystem.IO;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.Mvc;
namespaceDemo.Controllers
{
publicclassValidateController:Controller
{
publicFileResultConfirmCode()
{
//生成4位随机数消纤,并将其转为string型,传入session,4位数字由随机数从1000-9999中提取。
stringConfirmCode=string.Empty;
Random兆槐rand=newRandom();
ConfirmCode=rand.Next(1000,9999).ToString();
Session["QuickChannelConfirmCode"]=ConfirmCode;
Randomrand1=newRandom();
Randomrand2=newRandom();
intred=rand1.Next(50);
intgreen=rand2.Next(100);
intblue1=(red+green>400)?0:400-red-green;
intblue2=(blue1>255)?255:blue1;
Colorcol=Color.FromArgb(red,green,blue2);
//intimageWidth=ConfirmCode.Length*13;
Bitmapbmp=newBitmap(135,44);
Graphicsg=Graphics.FromImage(bmp);
g.Clear(Color.LightGray);
g.DrawRectangle(newPen(Color.LightGray,1),0,0,134,43);
Fontfont=newFont("Harrington",30);
Brushbrush=newSolidBrush(col);//col为上文随机出的颜色
Pointpo=newPoint(15,0);
g.DrawString(ConfirmCode,font,brush,po);
Response.ContentType="image/jpeg";
MemoryStreamms=new族桥友MemoryStream();
bmp.Save(ms,ImageFormat.Jpeg);
ms.Seek(0,SeekOrigin.Begin);
returnnewFileStreamResult(ms,"image/jpeg");
}
publicActionResultCheckCode(stringid)
{
//stringquickChannalConfirmCode=Request.QueryString["id"].ToString();
stringquickChannalConfirmCode=id.ToUpper();
if(Session["QuickChannelConfirmCode"]==null||"".Equals(Session["QuickChannelConfirmCode"].ToString()))
{
returnJson(false,JsonRequestBehavior.AllowGet);
}
stringyanzheng=Session["QuickChannelConfirmCode"].ToString();
Session.Remove("QuickChannelConfirmCode");
if(quickChannalConfirmCode==yanzheng)
{
returnJson(true,JsonRequestBehavior.AllowGet);
}
else
{
returnJson(false,JsonRequestBehavior.AllowGet);
}
}
}
}
在页面上这样调用:
<imgid="VerificationCodeImg"src="/Validate/ConfirmCode2"alt="验证码"/>
然后还要在页面加上验证:
<scripttype="text/javascript">
functionRefreshConfirmCode(){
varrad_num=parseInt(1000*Math.random());
$("#VerificationCodeImg").attr("src","/Validate/ConfirmCode/"+rad_num);
$("#YanZhengMa").val("");
}
$(function(){
$("#VerificationCodeImg").click(RefreshConfirmCode);
$("#LoginButton").click(function(event){
varthisForm=$("form").first();
if(thisForm.valid()){
varthisVerificationCode=$("#YanZhengMa").val();
if(thisVerificationCode){
$.getJSON('/Validate/CheckCode',{id:thisVerificationCode},function(json,textStatus){
if(!json){
RefreshConfirmCode();
thisForm.valid();
}
else{
thisForm.submit();
}
});
}
}
returnfalse;
});
});
</script>
‘柒’ asp.net验证码
添加一个checkcode.aspx文件,在cs中写入:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Drawing;
namespace EIMS
{
public partial class CheckCode : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
CreateCheckCodeImage(GenerateCheckCode());
}
private string GenerateCheckCode() //绘制4个随机蔽汪盯数或字母
{
int number;
char code;
string checkCode = String.Empty;
Random random = new Random();
for (int i = 0; i < 4; i++)
{
number = random.Next();
if (number % 2 == 0)
code = (char)('0' + (char)(number % 10));
else
code = (char)('A' + (char)(number % 26));
checkCode += code.ToString();
}
Response.Cookies.Add(new HttpCookie("CheckCode", 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 < 2; 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.Black), x1, y1, x2, y2);
}
Font font = new System.Drawing.Font("Arial", 12, (System.Drawing.FontStyle.Bold));
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();
}
}
}
}
再在要添加验证码处添加<asp:Image ID="Image1" runat="server" Height="27px" Width="77px"
imageurl="CheckCode.aspx"/>
即可
--------------------------------------------------------------------
Dreamweaver我很少用,不太了解,你在网上找一下解决方案吧
‘捌’ asp.net做登陆页面的验证码怎么写,求具体的操作和代码
网上找个验证码,基本上都是个aspx+aspx.cs这样,放个<img>标签,src为验证码地址,判断验证码用ajax,一般验证码都放session,判断下就可以,找不到我放个验证码给你
‘玖’ asp.net(C#)图片随机验证码的代码!不要在网上抄的!要自己测试成功的!
首先,新建文件:闭耐扰CreateImage.aspx
里面不用写代码,
CreateImage.aspx.cs 如下:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace CreateImage
{
/// <summary>
/// CreateImage 的摘要说明。
/// </轿旦summary>
public class CreateImage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string checkCode = CreateCode(4);
//用于验证
Session["CheckCode"] = checkCode;
CreateImages(checkCode);
}
/*产亩陆生验证码*/
public string CreateCode(int codeLength)
{
string so = "1,2,3,4,5,6,7,8,9,0,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
string[] strArr=so.Split(',');
string code = "";
Random rand=new Random();
for (int i = 0; i < codeLength; i++)
{
code+=strArr[rand.Next(0, strArr.Length)];
}
return code;
}
/*产生验证图片*/
public void CreateImages(string code)
{
Bitmap image = new Bitmap(60, 20);
Graphics g = Graphics.FromImage(image);
WebColorConverter ww=new WebColorConverter();
g.Clear((Color)ww.ConvertFromString("#FAE264"));
Random random = new Random();
//画图片的背景噪音线
for (int i = 0; i < 12; 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.LightGray), x1, y1, x2, y2);
}
Font font = new Font("Arial", 15, FontStyle.Bold | FontStyle.Italic);
System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(
new Rectangle(0,0,image.Width,image.Height),Color.Blue,Color.Gray,1.2f,true);
g.DrawString(code, font, brush, 0, 0);
//画图片的前景噪音点
for (int i = 0; i < 10; i++)
{
int x = random.Next(image.Width);
int y = random.Next(image.Height);
image.SetPixel(x, y, Color.White);
}
//画图片的边框线
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());
g.Dispose();
image.Dispose();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
之后只需要在调用的时候 填入<img src="CreateImage.aspx" align="middle">就可以
例如:新建WebForm1.aspx
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="CreateImage.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<img src="CreateImage.aspx" align="middle"><BR>
</form>
</body>
</html>
‘拾’ net用户名密码验证码
Session["Valid"滑喊] = my51aspx;
//以下三句,通过随机找一个现有图象产生一个画布Bitmap
string bgFilePath = Server.MapPath(".\\images\\bg" + new Random().Next(5) + ".jpg");//模让嫌随机找个图象
System.Drawing.Image imgObj = System.Drawing.Image.FromFile(bgFilePath);
Bitmap newBitmap = new Bitmap(imgObj, 290, 80);//建立位图对象
Graphics g = Graphics.FromImage(newBitmap);//根据上面创建的位图对象创建绘图面
SolidBrush brush = new SolidBrush(Color.Black);//设置画笔颜色
//定义一个含10种字体的数组
String[] fontFamily ={ "Arial", "Verdana", "Comic Sans MS", "Impact", "Haettenschweiler", "Lucida Sans Unicode", "Garamond", "Courier New", "Book Antiqua", "Arial Narrow" };
/旦手/通过循环,绘制每个字符,
for (int a = 0; a < my51aspx.Length; a++)
{
Font textFont = new Font(fontFamily[rd.Next(9)], 30, FontStyle.Bold);//字体随机,字号大小30,加粗
//每次循环绘制一个字符,设置字体格式,画笔颜色,字符相对画布的X坐标,字符相对画布的Y坐标
g.DrawString(my51aspx.Substring(a, 1), textFont, brush, 40 + a * 36, 20);
}
//保存画的图片到输出流中
newBitmap.Save(Response.OutputStream, ImageFormat.Gif);
}
}
}