Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 26th, 2007, 01:23 AM
Authorized User
 
Join Date: Jan 2007
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default CAPTCHA image .NET error/problem

Hi.

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:
Code:
<img src="TuringImage.aspx" alt="" />
My code on TuringImages.aspx have this code:
Code:
<%@ 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:
Code:
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






Similar Threads
Thread Thread Starter Forum Replies Last Post
CAPTCHA Code MunishBhatia ASP.NET 2.0 Basics 2 December 24th, 2007 03:49 AM
Captcha + E-mail with link verification ViagraFalls BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 13 September 24th, 2007 04:06 AM
How to create Captcha using VB Script compad Classic ASP Basics 2 September 12th, 2007 03:00 AM
Opinions sought re Captcha image use?? jimibt BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 6 April 9th, 2007 05:52 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.