Page 1 of 3

Shadow Text Maker

Posted: Wed Jan 06, 2010 10:19 am
by CodenStuff
Hello,

Its cold and snowing outside so while im inside keeping warm I decided to catch up on some overdue tutorials that people have been asking me to do for them. So here is a strange little application that turns your text into a nice image.

First start a new project and add the following controls to your main form:

PictureBox
4 Buttons
TextBox
ColorDialog
FontDialog


Now place the controls on your form however you like them and just to give you an idea of what the controls do heres a screenshot from the attached source-code:
sshot-6.png
OK once you have done your controls we need to get the code done so first enter these imports:
Code: Select all
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Drawing.Text
Imports System.Drawing.Drawing2D
Then below "Public Class Form.." add this code:
Code: Select all
 Inherits System.Windows.Forms.Form
    Private ConvertedTextImage As Bitmap
    Private Const ShadowIntense As Integer = 6
    Dim TextColor = Color.Blue, ShadowColor = Color.Gray
    Dim TextFont As New Font("Arial", 20, FontStyle.Bold)
    Protected Overloads Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        PictureBox1.Image = ConvertedTextImage
        MyBase.OnPaint(e)
    End Sub
We are going to use Button1 to change the color of our text so in the "Click_event" add this code:
Code: Select all
If ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            TextColor = ColorDialog1.Color
         End If
and we are going to use Button2 to change the color of our texts shadow so in the "Click_event" add this code:
Code: Select all
If ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            ShadowColor = ColorDialog1.Color
         End If
Button3 will be used to change our texts font so again in the "Click_event" add this code:
Code: Select all
 If FontDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            TextFont = FontDialog1.Font
        End If
now we use Button4 to generate our image from our text so add this code in its "Click_event":
Code: Select all
ConvertedTextImage = DirectCast(TextToShadowImage(TextBox1.Text, TextFont, TextColor, ShadowColor), Bitmap)
Finally we need our actual function that will turn our plain text into an image so add this code block just above "End Class":
Code: Select all
Public Shared Function TextToShadowImage(ByVal InText As String, ByVal TextFontStyle As Font, ByVal TColor As Color, ByVal SColor As Color) As Image
        Dim ShadowTextOutput As Bitmap = Nothing
        Using g As Graphics = Graphics.FromHwnd(IntPtr.Zero)
            Dim STSize As SizeF = g.MeasureString(InText, TextFontStyle)
            Using bmp As New Bitmap(CInt(STSize.Width), CInt(STSize.Height))
                Using gBmp As Graphics = Graphics.FromImage(bmp)
                    Using BrushBackground As New SolidBrush(Color.FromArgb(16, SColor.R, SColor.G, SColor.B))
                        Using BrushForground As New SolidBrush(TColor)
                            gBmp.SmoothingMode = SmoothingMode.HighQuality
                            gBmp.InterpolationMode = InterpolationMode.HighQualityBilinear
                            gBmp.TextRenderingHint = TextRenderingHint.AntiAliasGridFit
                            gBmp.DrawString(InText, TextFontStyle, BrushBackground, 0, 0)
                            ShadowTextOutput = New Bitmap(bmp.Width + ShadowIntense, bmp.Height + ShadowIntense)
                            Using gBmpOut As Graphics = Graphics.FromImage(ShadowTextOutput)
                                gBmpOut.SmoothingMode = SmoothingMode.HighQuality
                                gBmpOut.InterpolationMode = InterpolationMode.HighQualityBilinear
                                gBmpOut.TextRenderingHint = TextRenderingHint.AntiAliasGridFit
                                For x As Integer = 0 To ShadowIntense
                                    For y As Integer = 0 To ShadowIntense
                                        gBmpOut.DrawImageUnscaled(bmp, x, y)
                                    Next
                                Next
                                gBmpOut.DrawString(InText, TextFontStyle, BrushForground, ShadowIntense / 2, ShadowIntense / 2)
                            End Using
                        End Using
                    End Using
                End Using
            End Using
        End Using
        Return ShadowTextOutput
    End Function
Save build and run the application and you should now have a working shadow text maker.

Download Source-Code:
NiceTexteff.zip
Happy coding! cooll;

Re: Shadow Text Maker

Posted: Wed Jan 06, 2010 12:20 pm
by hungryhounduk
Hi Codenstuff
Nice cooll; wahooo;

You always seem to amaze me with these Great apps cooll;

Chris

Re: Shadow Text Maker

Posted: Wed Jan 06, 2010 5:54 pm
by Lewis
Love this :D Also im going to combine this with a button express clone i made :P

Re: Shadow Text Maker

Posted: Wed Jan 06, 2010 9:57 pm
by Miutubevids
Great Job But it Seems More of an Outline

Re: Shadow Text Maker

Posted: Mon Jan 17, 2011 11:14 am
by Dummy1912
Great app codenstuff

but so sad its not working with me.
nothing happens.

any idea?

Dummy1912

Re: Shadow Text Maker

Posted: Mon Jan 17, 2011 12:14 pm
by Skillful
Great tutorial Craig!! I'll use this in my Text Editor.

Re: Shadow Text Maker

Posted: Mon Jan 17, 2011 3:28 pm
by M1z23R
When i change the text nothing happens :/ When i click create button, also nothing happens :/

Re: Shadow Text Maker

Posted: Mon Jan 17, 2011 3:29 pm
by M1z23R
I think if it stats working for me i can rewrite your code into creating captcha-s :)

Re: Shadow Text Maker

Posted: Mon Jan 17, 2011 3:32 pm
by MrAksel
Its not hard to create captchas, tommorrow ill post my generator. It would be alot different than others.

Re: Shadow Text Maker

Posted: Mon Jan 17, 2011 11:38 pm
by code it
:D Great great great job!!!!!!!!!!!! cooll; cooll; cooll; cooll; cooll; cooll;