For i = 9 To 0 Step -1 ' 历经所有行
For ii = 0 To 3 ' 历经所有字
For iii = 1 To 10 ' 历经所有像素
' 逐行、逐字、逐像素地输出图像数据
If Rnd * 99 + 1 < cOdds Then ' 随机生成杂点
Response.BinaryWrite vColorData(0)
Else
Response.BinaryWrite vColorData(Mid(vNumberData(vCode(ii)), i * 10 + iii, 1))
End If
Next
Next
Next
End Sub
%>
Private Sub Class_Terminate()
Font.RemoveAll
Set Font = Nothing
End Sub
Public Property Get Width()
Width = Width_
End Property
Public Property Get Height()
Height = Height_
End Property
Public Property Get Version()
Version = "NetRube VerifyCode Class 1.0 Build 20041225"
End Property
Public Property Let BGroundColor(ByVal Color)
GlobalColorTable(0) = MakeColor(Color)
BGroundColorIndex = 0
End Property
Public Property Let FGroundColor(ByVal Color)
GlobalColorTable(1) = MakeColor(Color)
FGroundColorIndex = 1
End Property
Public Property Get Pixel(ByVal PX, ByVal PY)
If (PX > 0 And PX <= Width_) And (PY > 0 And PY <= Height_) Then
Pixel = AscB(MidB(Image, (Width_ * (PY - 1)) + PX, 1))
Else
Pixel = 0
End If
End Property
Public Property Let Pixel(ByVal PX, ByVal PY, PValue)
Dim Offset
PX = Int(PX)
PY = Int(PY)
PValue = Int(PValue)
Offset = Width_ * (PY - 1)
If (PX > 0 And PX <= Width_) And (PY > 0 And PY <= Height_) Then
Image = LeftB(Image, Offset + (PX - 1)) & ChrB(PValue) & RightB(Image, LenB(Image) - (Offset + PX))
End If
End Property
Public Sub Clear()
Image = String(Width_ * (Height_ + 1) / 2, ChrB(BGroundColorIndex) & ChrB(BGroundColorIndex))
End Sub
Public Sub Resize(ByVal NewWidth, ByVal NewHeight, RPreserve)
Dim OldImage, OldWidth, OldHeight
Dim CopyWidth, CopyHeight
Dim X, Y
If RPreserve Then
OldImage = Image
OldWidth = Width_
OldHeight = Height_
End If
Width_ = NewWidth
Height_ = NewHeight
Clear
If RPreserve Then
If NewWidth > OldWidth Then CopyWidth = OldWidth Else CopyWidth = NewWidth
If NewHeight > OldHeight Then CopyHeight = OldHeight Else CopyHeight = NewHeight
Width_ = NewWidth
Height_ = NewHeight
For Y = 1 To CopyHeight
For X = 1 To CopyWidth
Pixel(X, Y) = AscB(MidB(OldImage, (OldWidth * (Y - 1)) + X, 1))
Next
Next
End If
End Sub
Private Function ShiftLeft(SLValue, SLBits)
ShiftLeft = SLValue * (2 ^ SLBits)
End Function
Private Function ShiftRight(SRValue, SRBits)
ShiftRight = Int(SRValue / (2 ^ SRBits))
End Function
Private Function Low(LValue)
Low = LValue And &HFF
End Function
Private Function High(HValue)
High = ShiftRight(HValue, 8)
End Function
Private Function Blue(BValue)
Blue = Low(ShiftRight(BValue, 16))
End Function
Private Function Green(GValue)
Green = Low(ShiftRight(GValue, 8))
End Function
Private Function Red(RValue)
Red = Low(RValue)
End Function
Private Function MakeColor(MCValue)
MakeColor = CLng("&H" & Right(MCValue, 2) & Mid(MCValue, 4, 2) & Mid(MCValue, 2, 2))
End Function
Private Function GetWord(GWValue)
GetWord = ShiftLeft(AscB(RightB(GWValue, 1)), 8) Or AscB(LeftB(GWValue, 1))
End Function
Private Function MakeWord(MWValue)
MakeWord = ChrB(Low(MWValue)) & ChrB(High(MWValue))
End Function
Private Function MakeByte(MBValue)
MakeByte = ChrB(Low(MBValue))
End Function
Private Function UncompressedData()
Dim ClearCode, ChunkMax, EndOfStream
Dim UDData, UD, U
For U = 1 To LenB(Image) Step ChunkMax
UDData = UDData & MidB(Image, U, ChunkMax) & ChrB(ClearCode)
Next
For U = 1 To LenB(UDData) Step &HFF
UD = MidB(UDData, U, &HFF)
UncompressedData = UncompressedData & MakeByte(LenB(UD)) & UD
Next
UncompressedData = UncompressedData & MakeByte(&H00)
UncompressedData = UncompressedData & MakeByte(EndOfStream)
End Function
Private Function GetGColorTable()
Dim GGCT
GetGColorTable = ""
For GGCT = 0 To UBound(GlobalColorTable) - 1
GetGColorTable = GetGColorTable & MakeByte(Red(GlobalColorTable(GGCT)))
GetGColorTable = GetGColorTable & MakeByte(Green(GlobalColorTable(GGCT)))
GetGColorTable = GetGColorTable & MakeByte(Blue(GlobalColorTable(GGCT)))
Next
End Function
Private Function GetLColorTable()
Dim GLCT
GetLColorTable = ""
For GLCT = 0 To UBound(LocalColorTable) - 1
GetLColorTable = GetLColorTable & MakeByte(Red(LocalColorTable(GLCT)))
GetLColorTable = GetLColorTable & MakeByte(Green(LocalColorTable(GLCT)))
GetLColorTable = GetLColorTable & MakeByte(Blue(LocalColorTable(GLCT)))
Next
End Function
Private Function GlobalDescriptor()
GlobalDescriptor = 0
If GlobalColorTableFlag Then GlobalDescriptor = GlobalDescriptor Or ShiftLeft(1, 7)
GlobalDescriptor = GlobalDescriptor Or ShiftLeft(ColorResolution, 7)
If SortFlag Then GlobalDescriptor = GlobalDescriptor Or ShiftLeft(1, 3)
GlobalDescriptor = GlobalDescriptor Or GlobalColorTableSize
End Function
Private Function LocalDescriptor()
LocalDescriptor = 0
If LocalColorTableFlag Then LocalDescriptor = LocalDescriptor Or ShiftLeft(1, 7)
If InterlaceFlag Then LocalDescriptor = LocalDescriptor Or ShiftLeft(1, 6)
If SortFlag Then LocalDescriptor = LocallDescriptor Or ShiftLeft(1, 5)
LocalDescriptor = LocalDescriptor Or ShiftLeft(Reserved, 3)
LocalDescriptor = LocalDescriptor Or LocalColorTableSize
End Function
If GIF89a Then
If UseTransparency Then
ImageData = ImageData & MakeByte(GraphicControl)
ImageData = ImageData & MakeByte(&HF9)
ImageData = ImageData & MakeByte(&H04)
ImageData = ImageData & MakeByte(&H01)
ImageData = ImageData & MakeByte(&H00)
ImageData = ImageData & MakeByte(TransparentColorIndex)
ImageData = ImageData & MakeByte(&H00)
End If
If Comment <> "" Then
ImageData = ImageData & MakeByte(GraphicControl)
ImageData = ImageData & MakeByte(&HFE)
Text = Left(Comment, &HFF)
ImageData = ImageData & MakeByte(Len(Text))
For I = 1 To Len(Text)
ImageData = ImageData & MakeByte(Asc(Mid(Text, I, 1)))
Next
ImageData = ImageData & MakeByte(&H00)
End If
End If
For I1 = 0 To UBound(Letter) - 1
For I2 = 1 To Len(Text)
For I3 = 1 To Len(Font(Mid(Text, I2, 1))(I1))
VCIndex = CLng(Mid(Font(Mid(Text, I2, 1))(I1), I3, 1))
If VCIndex <> 0 Then
If VCColor Then
Randomize
VCIndex = Int(Rnd * 7)
End If
Pixel(VCX + ((I2 - 1) * Len(Letter(0))) + I3, VCY + I1) = VCIndex
End If
Next
Next
Next
End Sub
Public Sub Noises(Amount, NColor)
Dim NI, NIndex
For NI = 1 To Amount
NIndex = 1
If NColor Then
Randomize
NIndex = Int(Rnd * 7)
End If
Pixel(Int(Rnd * Width_), Int(Rnd * Height_)) = NIndex
Next
End Sub
End Class
%>
--------------------------------------------------
For j = 1 To nPixelHeight - 2
For i = 1 To nCharCount * nPixelWidth - 2
If Buf(j, i) = 0 Then
If ((Buf(j, i - 1) Or Buf(j + 1, i)) And 1) <> 0 Then
' 如果当前点是空白点,且上下左右四个点中有一个点是有色点,则该点做柔化处理
Buf(j, i) = 2
End If
End If
Next
Next
End Sub
Sub CDGen_NoisyDot()
' 对产生的位图进行噪点处理
Dim i, j, NoisyDot, CurDot
For j = 0 To nPixelHeight - 1
For i = 0 To nCharCount * nPixelWidth - 1
If Buf(j, i) <> 0 Then
NoisyDot = Int(Rnd * Rnd * nMaxSaturation)
Select Case nColorNoisyDotOdds
Case 0
CurDot = nMaxSaturation
Case 1
CurDot = 0
Case Else
CurDot = NoisyDot
End Select
If Rnd < nColorNoisyDotOdds Then Buf(j, i) = CurDot Else Buf(j, i) = nMaxSaturation
Else
NoisyDot = Int(Rnd * nMaxSaturation)
Select Case nBlankNoisyDotOdds
Case 0
CurDot = 0
Case 1
CurDot = nMaxSaturation
Case Else
CurDot = NoisyDot
End Select
If Rnd < nBlankNoisyDotOdds Then Buf(j, i) = CurDot Else Buf(j, i) = 0
End If
Next
Next
End Sub
Sub CDGen()
' 生成位图阵列
Dim i, Ch
DigtalStr = ""
CDGen_Clear
For i = 0 To nCharCount - 1
Ch = Mid(cCharSet, Int(Rnd * Len(cCharSet)) + 1, 1)
DigtalStr = DigtalStr + Ch
CDGen_Char Ch, i * nPixelWidth, 0
Next
CDGen_Blur
CDGen_NoisyDot
End Sub
Function HSBToRGB(vH, vS, vB)
' 将颜色值由HSB转换为RGB
Dim aRGB(3), RGB1st, RGB2nd, RGB3rd
Dim nH, nS, nB
Dim lH, nF, nP, nQ, nT
vH = (vH Mod 360)
If vS > 100 Then
vS = 100
ElseIf vS < 0 Then
vS = 0
End If
If vB > 100 Then
vB = 100
ElseIf vB < 0 Then
vB = 0
End If
If vS > 0 Then
nH = vH / 60
nS = vS / 100
nB = vB / 100
lH = Int(nH)
nF = nH - lH
nP = nB * (1 - nS)
nQ = nB * (1 - nS * nF)
nT = nB * (1 - nS * (1 - nF))
Select Case lH
Case 0
aRGB(0) = nB * 255
aRGB(1) = nT * 255
aRGB(2) = nP * 255
Case 1
aRGB(0) = nQ * 255
aRGB(1) = nB * 255
aRGB(2) = nP * 255
Case 2
aRGB(0) = nP * 255
aRGB(1) = nB * 255
aRGB(2) = nT * 255
Case 3
aRGB(0) = nP * 255
aRGB(1) = nQ * 255
aRGB(2) = nB * 255
Case 4
aRGB(0) = nT * 255
aRGB(1) = nP * 255
aRGB(2) = nB * 255
Case 5
aRGB(0) = nB * 255
aRGB(1) = nP * 255
aRGB(2) = nQ * 255
End Select
Else
aRGB(0) = (vB * 255) / 100
aRGB(1) = aRGB(0)
aRGB(2) = aRGB(0)
End If
HSBToRGB = ChrB(Round(aRGB(2), 0)) & ChrB(Round(aRGB(1), 0)) & ChrB(Round(aRGB(0), 0))
End Function
' 逐点输出位图阵列
If nColorHue = -1 Then
CurColorHue = Int(Rnd * 360)
ElseIf nColorHue = -2 Then
CurColorHue = 0
Else
CurColorHue = nColorHue
End If
For j = 0 To nPixelHeight - 1
For i = 0 To Len(DigtalStr) * nPixelWidth - 1
If nColorHue = -2 Then
Response.BinaryWrite HSBToRGB(CurColorHue, 0, 100 - Buf(nPixelHeight - 1 - j, i))
Else
Response.BinaryWrite HSBToRGB(CurColorHue, Buf(nPixelHeight - 1 - j, i), 100)
End If
Next
Next
End Sub
%>
Dim Buf(), DigtalStr
Dim Lines(), LineCount
Dim CursorX, CursorY, DirX, DirY
Randomize
Call CreatValidCode("GetCode")
Sub CDGen_Reset()
' 复位矢量笔和环境变量
LineCount = 0
CursorX = 0
CursorY = 0
' 初始的光笔方向是垂直向下
DirX = 0
DirY = 1
End Sub
Sub CDGen_Clear()
' 清空位图阵列
Dim i, j
ReDim Buf(nPixelHeight - 1, nCharCount * nPixelWidth - 1)
For j = 0 To nPixelHeight - 1
For i = 0 To nCharCount * nPixelWidth - 1
Buf(j, i) = 0
Next
Next
End Sub
Sub CDGen_PSet(X, Y)
' 在位图阵列上画点
Buf(Y, X) = 1
End Sub
Sub CDGen_Line(X1, Y1, X2, Y2)
' 在位图阵列上画线
Dim DX, DY, DeltaT, i
DX = X2 - X1
DY = Y2 - Y1
If Abs(DX) > Abs(DY) Then DeltaT = Abs(DX) Else DeltaT = Abs(DY)
For i = 0 To DeltaT
CDGen_PSet X1 + DX * i / DeltaT, Y1 + DY * i / DeltaT
Next
End Sub