BMP image rules: BMP files have 54 bytes of file headers, including the BMP file mark "BM", file size, start position, length, width, bitmap digits: 1/4/8/241,8 pixels (1 byte); 4/2 pixels (1 byte); 8/8 pixels (1 byte); 24/1 pixel (3 bytes ;). However, the simplest method is to first create an empty image of the same size on the canvas and record the information in the header.
The actual display part of the BMP file starts from the lower left corner and ends at the upper right corner. Each pixel of the file is recorded in detail. If it is represented by a 24-Bit Bitmap, it is represented by three bytes. Red indicates ff 00 ff, black indicates 00 00 00, and white indicates ff...
If we want to represent a number or letter, we can use a 10x10 array to represent it. For example, 1 is represented by the following array:
1111011111
1100011111
1111011111
1111011111
1111011111
1111011111
1111011111
1111011111
1111011111
1100000111
Of course, you can also use a larger array to represent a richer style.
After understanding the principle, we can use the program to implement it. We use the Response. BinaryWrite method to write the file header, and then use the program to write the file body.
The following is a program used to generate the IP address of the browser:
<%
Response. Expires =-9999
Response. AddHeader "cache-control", "no-cache"
Response. ContentType = "Image/BMP"
Const cCode = "0123456789." 'Data Value
Dim vColor (2)
VColor (0) = ChrB (0) & ChrB (0) & ChrB (0) 'black
VColor (1) = ChrB (255) & ChrB (255) & ChrB (255) 'White
Ip = request. ServerVariables ("http_x_forwarded_for ")'
If ip = "" then
Ip = request. ServerVariables ("remote_addr ")
End if
Ls = split (ip, ".",-) 'split the IP address
For j = 0 to 3 'Processing Group
If len (ls (j) <3 then' if the length is less than 3
Spac = ""
For k = 1 to 3-len (ls (j) 'plus 3-len Spaces
Spac = spac + ""
Next
Ls (j) = spac + ls (j) 'convert ls (j) with sufficient length)
End if
Next
Str = "" 'IP address string for secondary processing, over
For k = 0 to 3
Str = str + ls (k) + "."
Next
Str = left (str, 15)
Dim vCode (15) 'is processed as an array three times.
For x = 0 To 14
What is the value of vCode (x) = mid (str, x + 1, 1?
VCode (x) = instr (1, cCode, vCode (x), 1)-1' what is the value in the string?
'Response. write vCode (x )&"
"
Next
Dim vNumber (12)
VNumber (0) = "1110000111110111101111011110111101001011110100101111010010111101001011110111101111011110111110000111"
VNumber (1) = "1111011111110001111111110111111111011111111101111111110111111111011111111101111111110111111100000111"
VNumber (2) = "1110000111110111101111011110111111111011111111011111111011111111011111111011111111011110111100000011"
VNumber (3) = "1110000111110111101111011110111111110111111100111111111101111111111011110111101111011110111110000111"
VNumber (4) = "1111101111111110111111110011111110101111110110111111011011111100000011111110111111111011111111000011"
VNumber (5) = "1100000011110111111111011111111101000111110011101111111110111111111011110111101111011110111110000111"
VNumber (6) = "1111000111111011101111011111111101111111110100011111001110111101111011110111101111011110111110000111"
VNumber (7) = "1100000011110111011111011101111111101111111110111111110111111111011111111101111111110111111111011111"
VNumber (8) = "1110000111110111101111011110111101111011111000011111101101111101111011110111101111011110111110000111"
VNumber (9) = "1110001111110111011111011110111101111011110111001111100010111111111011111111101111011101111110001111"
VNumber (10) = "1111111111111111111111111111111111111111111111111111111111111111111111111111111111110011111111001111"
VNumber (11) = "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
Response. binaryWrite chrB (66) & chrB (77) & chrB (222) & chrB (17) & chrB (0) & chrB (0) & chrB (0) & chrB (0) & chrB (0) & chrB (0) & chrB (54 )&_
ChrB (0) & chrB (0) & chrB (0) & chrB (40) & chrB (0) & chrB (0) & chrB (0) & chrb( 150) & chrB (0) & chrB (0) & chrB (0) & chrB (10) & chrB (0) & chrB (0 )&_
ChrB (0) & chrB (1) & chrB (0) & chrB (24) & chrB (0) & chrB (0) & chrB (0) & chrB (0) & chrB (0) & chrb( 168) & chrB (17)
Response. binaryWrite chrB (0) & chrB (0) & chrB (0) & chrB (0) & chrB (0) & chrB (0) & chrB (0) & chrB (0) & chrB (0) & chrB (0) & chrB (0) & chrB (0 )&_
ChrB (0) & chrB (0) & chrB (0) & chrB (0) & chrB (0) & chrB (0)
Dim x, y, z
For x = 9 To 0 step-1 'row by row
For y = 0 To 14' verbatim
For z = 1 To 10' pixel-by-pixel R/G/B, because vColor () has defined each RGB value. If it is an 8-Bit Bitmap, use one byte.
Response. BinaryWrite vColor (Mid (vNumber (vCode (y), x * 10 + z, 1) 'Write stream
Next
Next
Response. BinaryWrite vColor (1) 'adds a line tail flag to each row
Next
%>
Of course, the flow generated by this program is a little inconsistent with the definition of the bitmap, and the picture is a bit oblique. Let's study it slowly...
The following is the Program for generating a color Random verification code on the internet I modified. The attachment always prompts that the file1 format is incorrect and has to be pasted below
<%
Response. ContentType = "Image/BMP"
Call Com_CreatValidCode ()
Sub Com_CreatValidCode ()
Randomize
Dim I, ii, iii
Const cAmount = 36' number of values
Const cCode = "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" 'value range
Dim vColorData (2)
VColorData (0) = "" 'black points must be converted to color points, which are not defined at the moment
VColorData (1) = ChrB (255) & ChrB (255) & ChrB (255) 'White spot
Dim vCode (4), vCodes 'generates a group of arbitrary numbers
For I = 0 To 3
VCode (I) = Int (Rnd * cAmount) 'array equals to total * Random Number
VCodes = vCodes & Mid (cCode, vCode (I) +) 'string equals to string plus subsequent values
Next
Session ("checkcode") = vCodes 'records the string value
Dim vNumberData (36)
VNumberData (0) = "1110000111110111101111011110111101001011110100101111010010111101001011110111101111011110111110000111"
VNumberData (1) = "1111011111110001111111110111111111011111111101111111110111111111011111111101111111110111111100000111"
VNumberData (2) = "1110000111110111101111011110111111111011111111011111111011111111011111111011111111011110111100000011"
VNumberData (3) = "1110000111110111101111011110111111110111111100111111111101111111111011110111101111011110111110000111"
VNumberData (4) = "1111101111111110111111110011111110101111110110111111011011111100000011111110111111111011111111000011"
VNumberData (5) = "1100000011110111111111011111111101000111110011101111111110111111111011110111101111011110111110000111"
VNumberData (6) = "1111000111111011101111011111111101111111110100011111001110111101111011110111101111011110111110000111"
VNumberData (7) = "1100000011110111011111011101111111101111111110111111110111111111011111111101111111110111111111011111"
VNumberData (8) = "1110000111110111101111011110111101111011111000011111101101111101111011110111101111011110111110000111"
VNumberData (9) = "1110001111110111011111011110111101111011110111001111100010111111111011111111101111011101111110001111"
VNumberData (10) = "1111011111111101111111101011111110101111111010111111101011111100000111110111011111011101111000100011"
VNumberData (11) = "1000000111110111101111011110111101110111110000111111011101111101111011110111101111011110111000000111"
VNumberData (12) = "1110000011110111101110111110111011111111101111111110111111111011111111101111101111011101111110001111"
VNumberData (13) = "1000001111110111011111011110111101111011110111101111011110111101111011110111101111011101111000001111"
VNumberData (14) = "1000000111110111101111011011111101101111110000111111011011111101101111110111111111011110111000000111"
VNumberData (15) = "1000000111110111101111011011111101101111110000111111011011111101101111110111111111011111111000111111"
VNumberData (16) = "1110000111110111011110111101111011111111101111111110111111111011100011101111011111011101111110001111"
VNumberData (17) = "1000100011110111011111011101111101110111110000011111011101111101110111110111011111011101111000100011"
VNumberData (18) = "1100000111111101111111110111111111011111111101111111110111111111011111111101111111110111111100000111"
VNumberData (19) = "1110000011111110111111111011111111101111111110111111111011111111101111111110111110111011111000011111"
VNumberData (20) = "1000100011110111011111011011111101011111110001111111010111111101101111110110111111011101111000100011"
VNumberData (21) = "1000111111110111111111011111111101111111110111111111011111111101111111110111111111011110111000000011"
VNumberData (22) = "1000100011110010011111001001111100100111110101011111010101111101010111110101011111010101111001010011"
VNumberData (23) = "1000100011110011011111001101111101010111110101011111010101111101100111110110011111011001111000110111"
VNumberData (24) = "1110001111110111011110111110111011111011101111101110111110111011111011101111101111011101111110001111"
VNumberData (25) = "1000000111110111101111011110111101111011110000011111011111111101111111110111111111011111111000111111"
VNumberData (26) = "1110001111110111011110111110111011111011101111101110111110111011111011101001101111011001111110001011"
VNumberData (27th) = "1000001111110111011111011101111101110111110000111111010111111101101111110110111111011101111000110011"
VNumberData (28) = "1110000011110111101111011110111101111111111001111111111001111111111011110111101111011110111100000111"
VNumberData (29) = "1000000011101101101111110111111111011111111101111111110111111111011111111101111111110111111110001111"
VNumberData (30) = "1000100011110111011111011101111101110111110111011111011101111101110111110111011111011101111110001111"
VNumberData (31) = "1000100011110111011111011101111101110111111010111111101011111110101111111010111111110111111111011111"
VNumberData (32) = "1001010011110101011111010101111101010111110101011111001001111110101111111010111111101011111110101111"
VNumberData (33) = "1000100011110111011111101011111110101111111101111111110111111110101111111010111111011101111000100011"
VNumberData (34) = "1000100011110111011111011101111110101111111010111111110111111111011111111101111111110111111110001111"
VNumberData (35) = "1100000011110111011111111101111111101111111110111111110111111111011111111011111111101110111100000011"
Response. binaryWrite ChrB (66) & ChrB (77) & ChrB (230) & ChrB (4) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (0) &_
ChrB (0) & ChrB (0) & ChrB (54) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (40) & ChrB (0) &_
ChrB (0) & ChrB (0) & ChrB (40) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (10) & ChrB (0) &_
ChrB (0) & ChrB (0) & ChrB (1) & ChrB (0)
Response. binaryWrite ChrB (24) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (0) & chrb( 176) & ChrB (4) &_
ChrB (0) & ChrB (0) & ChrB (18) & ChrB (11) & ChrB (0) & ChrB (0) & ChrB (18) & ChrB (11) &_
ChrB (0) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (0) & ChrB (0) &_
ChrB (0) & ChrB (0)
For I = 9 To 0 Step-1 'row
For ii = 0 To 3 'Words
For iii = 1 To 10' Pixel
If Mid (vNumberData (vCode (ii), I * 10 + iii, 1) = "0" then' generates a color point, minus a fixed value, which can make the color darker
Dim a, B, c
A = abs (rnd* 256-60)
B = abs (Rnd * 256-128)
C = abs (Rnd * 256-60)
VColorData (0) = ChrB (a) & ChrB (B) & ChrB (c)
Response. BinaryWrite vColorData (Mid (vNumberData (vCode (ii), I * 10 + iii, 1 ))
Else
Dim d, e, f' generates a color background. The color is light and noise can be randomly generated as the background.
D = abs (rndx 255)
E = abs (Rnd * 255)
F = abs (rndx 255)
If d + e + f> 580 then
VColorData (1) = ChrB (d) & ChrB (e) & ChrB (f)
Response. BinaryWrite vColorData (Mid (vNumberData (vCode (ii), I * 10 + iii, 1 ))
Else
Response. BinaryWrite vColorData (Mid (vNumberData (vCode (ii), I * 10 + iii, 1 ))
End if
End if
Next
Next
Next
End Sub
%>