• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 384
  • Last Modified:

how i generate CAPTCHA Image?

send me the correct captcha code sample...
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Drawing.Text;
using System.Drawing.Imaging;

/// <summary>
/// Summary description for Class1
/// </summary>
public class Class1
{
	
	private void GenerateImage()
    {
      // Create a new 32-bit bitmap image.
      Bitmap bitmap = new Bitmap(
        this.width,
        this.height,
        PixelFormat.Format32bppArgb);

      // Create a graphics object for drawing.
      Graphics g = Graphics.FromImage(bitmap);
      g.SmoothingMode = SmoothingMode.AntiAlias;
      Rectangle rect = new Rectangle(0, 0, this.width, this.height);

      // Fill in the background.
      HatchBrush hatchBrush = new HatchBrush(
        HatchStyle.SmallConfetti,
        Color.LightGray,
        Color.White);
      g.FillRectangle(hatchBrush, rect);

      // Set up the text font.
      SizeF size;
      float fontSize = rect.Height + 1;
      Font font;
      // Adjust the font size until the text fits within the image.
      do
      {
        fontSize--;
        font = new Font(
          this.familyName,
          fontSize,
          FontStyle.Bold);
        size = g.MeasureString(this.text, font);
      } while (size.Width > rect.Width);

      // Set up the text format.
      StringFormat format = new StringFormat();
      format.Alignment = StringAlignment.Center;
      format.LineAlignment = StringAlignment.Center;

      // Create a path using the text and warp it randomly.
      GraphicsPath path = new GraphicsPath();
      path.AddString(
        this.text,
        font.FontFamily,
        (int) font.Style,
        font.Size, rect,
        format);
      float v = 4F;
      PointF[] points =
      {
        new PointF(
          this.random.Next(rect.Width) / v,
          this.random.Next(rect.Height) / v),
        new PointF(
          rect.Width - this.random.Next(rect.Width) / v,
          this.random.Next(rect.Height) / v),
        new PointF(
          this.random.Next(rect.Width) / v,
          rect.Height - this.random.Next(rect.Height) / v),
        new PointF(
          rect.Width - this.random.Next(rect.Width) / v,
          rect.Height - this.random.Next(rect.Height) / v)
      };
      Matrix matrix = new Matrix();
      matrix.Translate(0F, 0F);
      path.Warp(points, rect, matrix, WarpMode.Perspective, 0F);

      // Draw the text.
      hatchBrush = new HatchBrush(
        HatchStyle.LargeConfetti,
        Color.LightGray,
        Color.DarkGray);
      g.FillPath(hatchBrush, path);

      // Add some random noise.
      int m = Math.Max(rect.Width, rect.Height);
      for (int i = 0; i < (int) (rect.Width * rect.Height / 30F); i++)
      {
        int x = this.random.Next(rect.Width);
        int y = this.random.Next(rect.Height);
        int w = this.random.Next(m / 50);
        int h = this.random.Next(m / 50);
        g.FillEllipse(hatchBrush, x, y, w, h);
      }

      // Clean up.
      font.Dispose();
      hatchBrush.Dispose();
      g.Dispose();

      // Set the image.
      this.image = bitmap;
    }

	}

Open in new window

0
sunda2010
Asked:
sunda2010
  • 5
  • 3
1 Solution
 
Jon500Commented:
This works for me:

Image image = ThirdPartyCAPCHALibrary.Image();

Regards,
Jon500
0
 
sunda2010Author Commented:
i dont need ThirdParty.. i need to generate by my own..
0
 
sunda2010Author Commented:
send me the correct code generation for captcha.......
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Jon500Commented:
What is wrong with the code you provided above? Can you provide any details? It's difficult to know how to advise....

(BTW, I meant CAPTCHA above.)

Thank you,
Jon500
0
 
sunda2010Author Commented:
there is no error in codings.. but its not displaying output.. i am newer to this captcha codings.. pls send me correct coding ti display output or send sample codings for this captcha... soon
0
 
sunda2010Author Commented:
i need asp.net codings....
0
 
Jon500Commented:
OK, I got it.

There's quite a bit of coding involved. Rather than reinvent the wheel on this one, please consider this solution. I have recommended it to other with much success:

http://www.codeproject.com/KB/aspnet/CaptchaImage.aspx

Cheers,
Jon500
0
 
sunda2010Author Commented:
i try that.. in that the error as "MISSING SOME NAME SPACE AND REFERENCES" i need some of them.. pls send me that.....
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now