I have this CAPTCHA image for .Net in C-Sharp and translate it into VB and as Code_Behind.
http://www.mbarrick.com/blog/d6plinks/20061221-01
If i run the site/script i get the site but there is not being showing an CAPTCHA image, Why not !?
http://www.kennelenggaard.dk/captcha.aspx
Hope someone can help me with this.
My code on Default.aspx have this line:
Expand|Select|Wrap|Line Numbers
- <img src="TuringImage.aspx" alt="" />
My code on TuringImages.aspx have this code:
Expand|Select|Wrap|Line Numbers
- <%@ Page Language="VB" AutoEventWireup="false" CodeFile="TuringImage.aspx.vb" Inherits="TuringImage" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" >
- <head runat="server">
- <title>TurningImage</title>
- </head>
- <body>
- </body>
- </html>
My code_behind for this site it then:
Expand|Select|Wrap|Line Numbers
- Imports System.IO
- Imports System.Collections
- Imports System.ComponentModel
- Imports System.Data
- Imports System.Drawing
- Imports System.Drawing.Drawing2D
- Imports System.Drawing.Imaging
- Imports System.Web
- Imports System.Web.SessionState
- Imports System.Web.UI
- Imports System.Web.UI.WebControls
- Imports System.Web.UI.HtmlControls
- Partial
- Class TuringImage
- Inherits System.Web.UI.Page
- Private random As Random = New Random
- Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
- 'Width and height of image
- Dim width As Integer = 200
- Dim height As Integer = 50
- Dim familyName As String = "Times New Roman"
- 'String imageText = "123456";
- Dim imageText As String = Me.Session("TuringImageText").ToString
- 'Create a new 32-bit bitmap image.
- Dim bitmap As System.Drawing.Image = New Bitmap(width, height, PixelFormat.Format32bppArgb)
- 'Create a graphics object for drawing.
- Dim g As Graphics = Graphics.FromImage(bitmap)
- g.SmoothingMode = SmoothingMode.AntiAlias
- Dim rect As Rectangle = New Rectangle(0, 0, width, height)
- 'Fill in the background.
- Dim hatchBrush As HatchBrush = New HatchBrush(HatchStyle.SmallConfetti, Color.LightGray, Color.White)
- g.FillRectangle(hatchBrush, rect)
- 'Set up the text font.
- Dim size As SizeF
- Dim fontSize As Single = rect.Height + 1
- Dim font As Font
- 'Adjust the font size until the text fits within the image.
- Do
- System.Math.Max(System.Threading.Interlocked.Decrement(CLng(fontSize)), fontSize + 1)
- font = New Font(familyName, fontSize, FontStyle.Bold)
- size = g.MeasureString(imageText, font)
- Loop While size.Width > rect.Width
- 'Set up the text format.
- Dim format As StringFormat = New StringFormat
- format.Alignment = StringAlignment.Center
- format.LineAlignment = StringAlignment.Center
- 'Create a path using the text and warp it randomly.
- Dim path As GraphicsPath = New GraphicsPath
- path.AddString(imageText, font.FontFamily, CType(font.Style, Integer), font.Size, rect, format)
- Dim v As Single = 4.0F
- Dim points As PointF() = {New PointF(Me.random.Next(rect.Width) / v, Me.random.Next(rect.Height) / v), New PointF(rect.Width - Me.random.Next(rect.Width) / v, Me.random.Next(rect.Height) / v), New PointF(Me.random.Next(rect.Width) / v, rect.Height - Me.random.Next(rect.Height) / v), New PointF(rect.Width - Me.random.Next(rect.Width) / v, rect.Height - Me.random.Nex(rect.Height) / v)}
- Dim matrix As Matrix = New Matrix
- matrix.Translate(0.0F, 0.0F)
- path.Warp(points, rect, matrix, WarpMode.Perspective, 0.0F)
- 'Draw the text.
- hatchBrush = New HatchBrush(HatchStyle.LargeConfetti, Color.LightGray, Color.DarkGray)
- g.FillPath(hatchBrush, path)
- 'Add some random noise.
- Dim m As Integer = Math.Max(rect.Width, rect.Height)
- Dim i As Integer = 0
- While i < CType((rect.Width * rect.Height / 30.0F), Integer)
- Dim x As Integer = Me.random.Next(rect.Width)
- Dim y As Integer = Me.random.Next(rect.Height)
- Dim w As Integer = Me.random.Next(m / 50)
- Dim h As Integer = Me.random.Next(m / 50)
- g.FillEllipse(hatchBrush, x, y, w, h)
- System.Math.Min(System.Threading.Interlocked.Increment(i), i - 1)
- End While
- 'Change the response headers to output a JPEG image.
- Me.Response.Clear()
- Me.Response.ContentType = "image/jpeg"
- bitmap.Save(Me.Response.OutputStream, ImageFormat.Jpeg)
- 'Clean up.
- 'font.Dispose();
- hatchBrush.Dispose()
- g.Dispose()
- End Sub
- End Class