Shadow Text Maker
Posted: Wed Jan 06, 2010 10:19 am
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: OK once you have done your controls we need to get the code done so first enter these imports:
Download Source-Code: Happy coding! cooll;
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: OK once you have done your controls we need to get the code done so first enter these imports:
Code: Select all
Then below "Public Class Form.." add this code:Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Drawing.Text
Imports System.Drawing.Drawing2D
Code: Select all
We are going to use Button1 to change the color of our text so in the "Click_event" add this code: 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
Code: Select all
and we are going to use Button2 to change the color of our texts shadow so in the "Click_event" add this code:If ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
TextColor = ColorDialog1.Color
End If
Code: Select all
Button3 will be used to change our texts font so again in the "Click_event" add this code:If ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
ShadowColor = ColorDialog1.Color
End If
Code: Select all
now we use Button4 to generate our image from our text so add this code in its "Click_event": If FontDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
TextFont = FontDialog1.Font
End If
Code: Select all
Finally we need our actual function that will turn our plain text into an image so add this code block just above "End Class":ConvertedTextImage = DirectCast(TextToShadowImage(TextBox1.Text, TextFont, TextColor, ShadowColor), Bitmap)
Code: Select all
Save build and run the application and you should now have a working shadow text maker.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
Download Source-Code: Happy coding! cooll;