Do you know how to use Adodb.Stream to create color verification codes? Today, the editor of the Foxin Technology Channel demonstrates the operation method for you in an example. I hope it will be helpful to you who learn this knowledge.
The code copy is as follows:Response.buffer = true
NumCode
Function NumCode()
Response.Expires = -1
Response.AddHeader "Pragma","no-cache"
Response.AddHeader "cache-ctrol","no-cache"
dim zNum,i,j
dim Ados,Ados1
Randomize timer
Generate random four-digit numbers:
zNum = cint(8999*Rnd+1000)
Pass to session
Session("GetCode") = zNum
This for loop is to put random numbers into an array with subscript 3, which is convenient for providing the subsequent array transformation
dim zimg(3),NStr
NStr=cstr(zNum)
For i=0 to 3
zimg(i)=cint(mid(NStr,i+1,1))
Next
dim Pos
'Define two ADODB.Stream binary objects for image data operation:
set Ados=Server.CreateObject("Adodb.Stream")
Ados.Mode=3
Ados.Type=1
Ados.Open
set Ados1=Server.CreateObject("Adodb.Stream")
Ados1.Mode=3
Ados1.Type=1
Ados1.Open
'Load 0~9 digital data 10x100, Gbr array data, each 320 byte, 10 digits 3200 byte
'BGR one point, 10x10 points one number, one point three bytes (8 bits in binary, 00~FF in hexadecimal)
'A row of 10 dots 30 bytes + end of line mark 00 00 2 bytes 32 bytes, so a 10x100 image with a width smaller than the length of each digit 10x10 is 320 bytes
'If the length is larger than the width, there will be no end mark of line 0000, directly 300 bytes
These are the BMP 24bit data details
'As for the head, it is also very simple, including length and width, image start marking, etc. ~~ It is only 54 bytes, far less complicated than jpg or something
Ados.LoadFromFile(Server.mappath("body.Fix"))
Ados1.write Ados.read(1280)
'The first for loop extracts the corresponding four numbers from the 10X100 digital array in the order of random numbers generated
But vertical array of numbers
for i=0 to 3
Ados.Position=(9-zimg(i))*320
Ados1.Position=i*320
Ados1.write ados.read(320)
next
'Clear the data of the used ADOS and call in the header file that replaces the new image header 54 bytes
Ados.LoadFromFile(Server.mappath("head.fix"))
Pos=lenb(Ados.read())
Ados.Position=Pos 'Specify the Pos position, and you can offset the position by 54 bytes to add graphic data
The second for loop performs array transformation of numbers, converting vertical blocks into horizontal blocks
The method is to extract 4 times of 320 bytes and write to the ados object, and then extract the image data that is offset from the second line.
30 bytes is because bmp width is greater than long without 00 00 line end mark
for i=0 to 9 step 1
for j=0 to 3
Ados1.Position=i*32+j*320
Ados.Position=Pos+30*j+i*120
Ados.write ados1.read(30)
next
next
Ados.Position=0
response.BinaryWrite sends image data directly to the client
Response.ContentType = "image/BMP"
Response.BinaryWrite Ados.read()
Ados.Close:set Ados=nothing
Ados1.Close:set Ados1=nothing
End Function
The above article is the editor of the Error New Technology Channel compiled by you using Adodb.Stream to create color verification codes. I believe everyone has learned these operating methods. The Error New Technology Channel Network will continue to organize technical expertise for you. I hope you will continue to pay attention to us!