ASP图象组件shotgraph生成图片验证码的代码

来源:互联网 发布:java教学管理系统源码 编辑:程序博客网 时间:2024/05/23 11:59

 

文本文字过程如下:
使用时,请注意FontSmoothing这个属性:
它是用来定义文字是否防锯齿的。
0 - 使用系统默认设置
1 - 不防锯齿
2 - 防锯齿

<%
Response.Contenttype
="image/gif"
Set g=CreateObject("shotgraph.image")
g.CreateImage 
320,200,16
g.SetColor 
0,255,255,255
g.SetColor 
1,0,0,0
g.SetBgColor 
0
g.SetTextColor 
1
g.FillRect 
0,0,320,200
g.FontSmoothing
=1
g.CreateFont 
"Arial",0,42,0,True,False,False,False
g.TextOut 
0,30,"Non-Antialiased"
g.FontSmoothing
=2
g.CreateFont 
"Arial",0,42,0,True,False,False,False
g.TextOut 
0,120,"Antialiased"
g.BuildPalette 
2
Response.BinaryWrite g.GifImage(
-1,0,"")
%
>

 

 

ychar="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" '将数字和大写字母组成一个字符串 
   yc=split(char,","'将字符串生成数组 
   ycodenum=4 
   
for i=1 to ycodenum 
   
Randomize 
   ycode
=ycode&yc(Int((35*Rnd))) '数组一般从0开始读取,所以这里为35*Rnd 
   next 
   
   Response.Clear 
   Response.ContentType
="image/gif" 
   
set obj=Server.CreateObject("shotgraph.image"
   x
=55 '图片的宽 
   y=26 '图片的高 
   obj.CreateImage x,y,8 '8是图片的颜色8位 
   obj.SetColor 0,55,126,222 
   obj.SetColor 
1,255,255,255 
   
   obj.CreatePen 
"PS_SOLID",1,0 
   obj.SetBgColor 
0 
   obj.Rectangle 
0,0,x-1,y-1 
   obj.SetBkMode 
"TRANSPARENT" 
   obj.CreateFont 
"Arial",136,18,1,False,False,False,False 
   obj.SetTextColor 
1 
   obj.TextOut 
5,4,ycode&" " 
   
   img
=obj.GifImage(-1,1,""
   Response.BinaryWrite (img)