说明:
.net万岁...
.netframework的类库真是太强了,用GDI+可以干N多N多事情.
广告时间:
shawl.qiuC#CMS系统预计40天后开始编码,现在逐步设计中,免得到时求职说什么什么作品...唉.
PS:今天求职真是惨不忍睹,谁要招网页相关的请联系13435580019,邱先生.
什么地方俺都去,工资只要能过活就行,但是食宿问题得解决.
shawl.qiu
2007-02-01
http://blog.csdn.net/btbtd
classcheckcode:
复制代码 代码如下:
<%@PageLanguage="C#"AutoEventWireup="True"%>
<%@importNamespace="System.Drawing"%>
<%@importNamespace="System.Drawing.Drawing2D"%>
<%@importNamespace="System.Web"%>
<scriptrunat="server">
privatevoidPage_Load(objectsender,System.EventArgse)
{
StringsRndStr=checkcode.rndStr(4);
checkcode.general(sRndStr);
}
/*-----------------------------------------------------------------------------------*
*shawl.qiuc#.netcheckcodeclassv1.0
*-----------------------------------------------------------------------------------*/
//---------------------------------------------------------------------beginclasscheckcode
publicclasscheckcode
{
//-----------------------------------beginevent
publiccheckcode()
{
}
~checkcode()
{
}
//-----------------------------------endevent
//-----------------------------------beginpublicconstant
//-----------------------beginabout
publicconstStringauSubject="shawl.qiuc#.netcheckcodeclass";
publicconstStringauVersion="v1.0";
publicconstStringau="shawl.qiu";
publicconstStringauEmail="shawl.qiu@gmail.com";
publicconstStringauBlog="http://blog.csdn.net/btbtd";
publicconstStringauCreateDate="2007-2-1";
//-----------------------endabout
//-----------------------------------endpublicconstant
//-----------------------------------beginpublicstaticmethod
publicstaticvoidgeneral(StringsCc)
{
Int32ccLen=sCc.Length;
StringccFtFm="Arial";
Int32ccFtSz=12;
Int32ccWidth=ccLen*ccFtSz+1;
Int32ccHeight=ccFtSz+5;
using(BitmapoImg=newBitmap(ccWidth,ccHeight))
{
using(GraphicsoGpc=Graphics.FromImage(oImg))
{
HatchBrushhBrush=newHatchBrush(HatchStyle.DashedVertical,
Color.Yellow,Color.Silver);
oGpc.FillRectangle(hBrush,0,0,ccWidth,ccWidth);
oGpc.DrawString(sCc,newSystem.Drawing.Font(ccFtFm,ccFtSz,FontStyle.Bold),
newSystem.Drawing.SolidBrush(Color.Black),0,0);
//-----------------------边框
PenblackPen=newPen(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);
}
}
}//endpublicstaticvoidgeneral
publicstaticStringrndStr(Int32len)
{
StringsTemp="";
StringsForRnd="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(',');
RandomoRnd=newRandom();
Int32iArLen=aRnd.Length;
for(Int32i=0;i<len;i++)
{
sTemp+=aRnd[oRnd.Next(0,iArLen)];
}
returnsTemp;
}//endpublicstaticStringrndStr
//-----------------------------------endpublicstaticmethod
//-----------------------------------beginprivatestaticmethod
privatestaticvoidwriteImg(BitmapoImg)
{
using(System.IO.MemoryStreamms=newSystem.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());
}
}//endprivatestaticvoidwriteImg
}
//---------------------------------------------------------------------endclasscheckcode
</script>
【c# .net 生成图片验证码的代码】相关文章: