Session ("gif") = RndNum (5)
Me. IMG1.Src = "../vendor_admin/random_image.aspx"
Random_image.aspx:
Imports System. Drawing. Drawing2D
Imports System. Drawing. Imaging
Imports System. Drawing. Text
Imports System. Drawing
Imports System. Text
Partial Class public_random_image
Inherits System. Web. UI. Page
Protected Sub Page_Load (ByVal sender As Object, ByVal e As System. EventArgs) Handles Me. Load
Dim ImagePath As String = "~ /Image/Validator.jpg"
Dim gif As String = Session ("gif") 'rndnum (5)
Dim _ text () As Char = gif. ToCharArray (0, gif. Length)
Gif = _ text (0 ). toString + "" + _ text (1 ). toString + _ text (2 ). toString + "" + _ text (3 ). toString + "" + _ text (4 ). toString
'/Create a Bmp bitmap
Dim bitMapImage As Bitmap = New System. Drawing. Bitmap (Server. MapPath (ImagePath ))
Dim graphicImage As Graphics = Graphics. FromImage (bitMapImage)
'/Set the output mode of the paint brush
GraphicImage. SmoothingMode = SmoothingMode. HighQuality 'smoothingmode. HighSpeed
'/Add a text string
GraphicImage. DrawString (gif, New Font ("Arial", 15, FontStyle. Bold), SystemBrushes. WindowText, New Point (0, 0 ))
'/Set the image output format
Response. ContentType = "image/jpeg"
'/Save the data stream
BitMapImage. Save (Response. OutputStream, ImageFormat. Jpeg)
'/Release the occupied Resources
GraphicImage. Dispose ()
BitMapImage. Dispose ()
End Sub
End Class
RndNum class:
'Function name: RndNum
'Function parameter: VcodeNum -- set the number of digits of the returned random string
'Function: generate a random string mixed with numbers and characters
Function RndNum (ByVal VcodeNum) As String
Dim Vchar As String = ", 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"
Dim VcArray () As String = Split (Vchar, ",") 'generates an array of strings
Dim VNum As String = ""
Dim I As Byte
For I = 1 To VcodeNum
Randomize ()
VNum = VNum & VcArray (Int (35 * Rnd () 'array is generally read from 0, so here it is 35 * Rnd
Next
Return VNum
'While (iNum = Convert. ToInt32 (VcArray. Length * random. NextDouble () = VcArray. Length
'Inum = Convert. ToInt32 (VcArray. Length * random. NextDouble ())
'End While
'Vnum + = VcArray (iNum)
End Function