C# method need for converting text to graphics

  • Thread starter Thread starter Stratum
  • Start date Start date
S

Stratum

I'm looking for some method, possibly in a .Net class that I don't
about, for converting a text image to an image file in GIF or
JPEG format. The application is a form (could be a Web form
or a Windows form on an Internet-connected computer) where
the user types the contents of a randomly generated string
which is displayed in the form of an image.

You would encounter such a form, for instance, when
registering a software product, or submitting some kind
of information on a form that you don't want submitted
by an automated mass mailer... in other words, a spammer.
The string on the image must be manually typed
in order to submit the form.

Generating the string is no problem. Rasterizing it to
an image is the big deal.

Anyone know of a method, preferably in C#?
 
I'm looking for some method, possibly in a .Net class that I don't
about, for converting a text image to an image file in GIF or
JPEG format. The application is a form (could be a Web form
or a Windows form on an Internet-connected computer) where
the user types the contents of a randomly generated string
which is displayed in the form of an image.

[...]
Generating the string is no problem. Rasterizing it to
an image is the big deal.

Anyone know of a method, preferably in C#?

Do you want a captcha? Or just a bitmap with some text? If the latter,
it's not hard at all in .NET. Just create a Bitmap instance the size you
want, use Graphics.FromImage() to get a Graphics instance that will draw
into the Bitmap, and call Graphics.DrawString() to draw the text
graphically into your Bitmap instance. Finally, use the Image.Save()
method on the Bitmap instance to save the image out in whatever format you
want (but if you're using this for an online application, it may be that
you can just send the Bitmap back to the client directly without saving it
to a file).

If you want a captcha, you need to do all of the above, plus whatever
obfuscation of the text you want. I recommend Google for learning more
about specific captcha implementations. I'm not aware of any .NET support
for that specifically.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top