' Draw the words overlaid on each other.
Private Function MakeCaptchaImage(ByVal wid As Integer, _
ByVal hgt As Integer, ByVal the_font As Font, ByVal _
word1 As String, ByVal word2 As String) As Image
Dim bm As New Bitmap(wid, hgt)
Dim gr As Graphics = Graphics.FromImage(bm)
' Draw the first word, offset horizontally by a random
' amount.
Dim size1 As SizeF = gr.MeasureString(word1, the_font)
Dim rnd As New Random
Dim x As Single = rnd.Next(0, CInt(wid - size1.Width))
gr.DrawString(word1, the_font, Brushes.Blue, x, 0)
' Draw the second word over the first,
' offset vertically a bit and horizontally
' by a random amount.
Dim size2 As SizeF = gr.MeasureString(word2, the_font)
x = rnd.Next(0, CInt(wid - size2.Width))
Dim y As Integer = CInt(size2.Height / 3)
If y > CInt(hgt - size2.Height) Then _
y = CInt(hgt - size2.Height)
gr.DrawString(word2, the_font, Brushes.Blue, x, y)
Return bm
End Function
|