473,320 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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:
Expand|Select|Wrap|Line Numbers
  1. <img src="TuringImage.aspx" alt="" />
  2.  

My code on TuringImages.aspx have this code:
Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" AutoEventWireup="false" CodeFile="TuringImage.aspx.vb" Inherits="TuringImage" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" >
  4. <head runat="server">
  5. <title>TurningImage</title>
  6. </head>
  7. <body>
  8. </body>
  9. </html>
  10.  

My code_behind for this site it then:
Expand|Select|Wrap|Line Numbers
  1. Imports System.IO
  2. Imports System.Collections
  3. Imports System.ComponentModel
  4. Imports System.Data
  5. Imports System.Drawing
  6. Imports System.Drawing.Drawing2D
  7. Imports System.Drawing.Imaging
  8. Imports System.Web
  9. Imports System.Web.SessionState
  10. Imports System.Web.UI
  11. Imports System.Web.UI.WebControls
  12. Imports System.Web.UI.HtmlControls
  13.  
  14. Partial
  15. Class TuringImage
  16. Inherits System.Web.UI.Page
  17. Private random As Random = New Random
  18. Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
  19. 'Width and height of image
  20. Dim width As Integer = 200
  21. Dim height As Integer = 50
  22. Dim familyName As String = "Times New Roman"
  23. 'String imageText = "123456";
  24. Dim imageText As String = Me.Session("TuringImageText").ToString
  25. 'Create a new 32-bit bitmap image.
  26. Dim bitmap As System.Drawing.Image = New Bitmap(width, height, PixelFormat.Format32bppArgb)
  27. 'Create a graphics object for drawing.
  28. Dim g As Graphics = Graphics.FromImage(bitmap)
  29. g.SmoothingMode = SmoothingMode.AntiAlias
  30. Dim rect As Rectangle = New Rectangle(0, 0, width, height)
  31. 'Fill in the background.
  32. Dim hatchBrush As HatchBrush = New HatchBrush(HatchStyle.SmallConfetti, Color.LightGray, Color.White)
  33. g.FillRectangle(hatchBrush, rect)
  34. 'Set up the text font.
  35. Dim size As SizeF
  36. Dim fontSize As Single = rect.Height + 1
  37. Dim font As Font
  38. 'Adjust the font size until the text fits within the image.
  39. Do
  40. System.Math.Max(System.Threading.Interlocked.Decrement(CLng(fontSize)), fontSize + 1)
  41. font = New Font(familyName, fontSize, FontStyle.Bold)
  42. size = g.MeasureString(imageText, font)
  43. Loop While size.Width > rect.Width
  44. 'Set up the text format.
  45. Dim format As StringFormat = New StringFormat
  46. format.Alignment = StringAlignment.Center
  47. format.LineAlignment = StringAlignment.Center
  48. 'Create a path using the text and warp it randomly.
  49. Dim path As GraphicsPath = New GraphicsPath
  50. path.AddString(imageText, font.FontFamily, CType(font.Style, Integer), font.Size, rect, format)
  51. Dim v As Single = 4.0F
  52. 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)}
  53. Dim matrix As Matrix = New Matrix
  54. matrix.Translate(0.0F, 0.0F)
  55. path.Warp(points, rect, matrix, WarpMode.Perspective, 0.0F)
  56. 'Draw the text.
  57. hatchBrush = New HatchBrush(HatchStyle.LargeConfetti, Color.LightGray, Color.DarkGray)
  58. g.FillPath(hatchBrush, path)
  59. 'Add some random noise.
  60. Dim m As Integer = Math.Max(rect.Width, rect.Height)
  61. Dim i As Integer = 0
  62. While i < CType((rect.Width * rect.Height / 30.0F), Integer)
  63. Dim x As Integer = Me.random.Next(rect.Width)
  64. Dim y As Integer = Me.random.Next(rect.Height)
  65. Dim w As Integer = Me.random.Next(m / 50)
  66. Dim h As Integer = Me.random.Next(m / 50)
  67. g.FillEllipse(hatchBrush, x, y, w, h)
  68. System.Math.Min(System.Threading.Interlocked.Increment(i), i - 1)
  69. End While
  70. 'Change the response headers to output a JPEG image.
  71. Me.Response.Clear()
  72. Me.Response.ContentType = "image/jpeg"
  73. bitmap.Save(Me.Response.OutputStream, ImageFormat.Jpeg)
  74. 'Clean up.
  75. 'font.Dispose();
  76. hatchBrush.Dispose()
  77. g.Dispose()
  78. End Sub
  79. End Class 
  80.  
Mar 26 '07 #1
0 1390

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Krishna Kumar | last post by:
Hai all, I am doing a project in .net and in that project I have a problem in capturing text from an image. i.e images like CAPTCHA images . which has inbuilt text with in the image.So,...
0
by: aaronwmail-usenet | last post by:
Announcing SkimpyGimpy Support for PNG image CAPTCHA generation and PNG canvases. You can now use SkimpyGimpy to generate CAPTCHA text representations as PNG image files in addition to...
7
by: mitchell | last post by:
hi i m using IE 6.0. i want to refresh just the captcha part when the user clicks on an image. i searched for articles on it and got a fairly good understanding of it. but i m still unable to...
4
by: xeiter | last post by:
Hi, I have a captcha script on my website located at /captcha.php. What it does it generates an image with the code, displays the image (gd2) and saves the value of the code in session. How do I...
11
by: Twayne | last post by:
Hi, Learning PHP code; playing with various methods of generating captcha codes: In the code below, how would I change the size of the text displayed in the captcha code? Is it even possible...
7
by: =?Utf-8?B?bWF0dCBw?= | last post by:
Steve Orr has a neat Captcha control: http://steveorr.net/articles/CAPTCHASP.aspx but aside from "dragging the control onto your toolbox.." Does anyone have any installation instructions: e.g....
0
by: readnlearn | last post by:
hai, i have written this below code for displaying captcha image whenever i entered incorrect uname,password in login page. for that i disable the controls of captcha like textbox,labels,button and...
1
by: sb5309 | last post by:
In CAPTCHA, one starts a session, name it, and keep the verification code as this: $_SESSION = $veristr; When an end-user clicks SUBMIT, the server script will verify the code as this: ...
10
by: jeddiki | last post by:
Hi, I have a captcha script which should pick up a background image and add some random letters to it and re-display This is the part of the form that the captcha image is part of: <span...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.