Adapting code for halo around text

Blake81

Well-known member
Joined
Feb 23, 2006
Messages
304
Location
Georgia, USA
Programming Experience
1-3
I found an earlier post about adding a halo around text, and I am trying to adapt it for some code I have already written for images that I'm using on my message forums. I haven't worked with using a matrix before, so I'm not sure how to make the change to this. I think the halo isn't showing up because I moved the text where I wanted it on the image without changing the matrix. Could someone help me make the changes, or show me what this matrix is doing so that I can put the halo back? In this code, the word "Welcome" is where I want it, so the rest of the code just needs to change to put the halo back. Thanks for any help.

VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Button1_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] Button1.Click
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] pth [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Drawing2D.GraphicsPath()
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] bmp2 [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Image
bmp2 = Image.FromFile([/SIZE][SIZE=2][COLOR=#800000]"C:\Documents and Settings\Owner\Desktop\form.png"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] bmp3 [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Image = Image.FromFile([/SIZE][SIZE=2][COLOR=#800000]"C:\Documents and Settings\Owner\Desktop\lightning.jpg"[/COLOR][/SIZE][SIZE=2])
g = Graphics.FromImage(bmp)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] f [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Drawing.Font
f = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Font([/SIZE][SIZE=2][COLOR=#800000]"Arial"[/COLOR][/SIZE][SIZE=2], 60, FontStyle.Regular, GraphicsUnit.Pixel)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] bg [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Drawing.Drawing2D.LinearGradientBrush
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] rec [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Rectangle
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] rec1 [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Rectangle
rec1.Width = PictureBox1.Width - 100
rec1.Height = PictureBox1.Image.Height
rec1.X = PictureBox1.Location.X + 40
rec1.Y = PictureBox1.Location.Y
rec.X = PictureBox1.Location.X - 2
rec.Y = PictureBox1.Location.Y
rec.Width = PictureBox1.Image.Width - 10
rec.Height = PictureBox1.Height
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] bg2 [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Drawing.Drawing2D.LinearGradientBrush
bg2 = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Drawing.Drawing2D.LinearGradientBrush(rec1, Color.Black, Color.DarkBlue, Drawing2D.LinearGradientMode.Vertical)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] mbrush [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Drawing.TextureBrush
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] mbrush2 [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Drawing.TextureBrush
mbrush = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Drawing.TextureBrush(bmp2)
mbrush2 = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Drawing.TextureBrush(bmp3)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] tcolor [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Color
tcolor = Color.FromArgb(10, Color.Yellow.R, Color.Yellow.G, Color.Yellow.B)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] tbrush [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] System.Drawing.Drawing2D.LinearGradientBrush(rec, Color.BlanchedAlmond, Color.BlanchedAlmond, Drawing2D.LinearGradientMode.Horizontal)
tbrush.SetSigmaBellShape(0.5)
bg = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Drawing.Drawing2D.LinearGradientBrush(rec, Color.Maroon, Color.LightGray, Drawing2D.LinearGradientMode.ForwardDiagonal)
g.FillRectangle(mbrush, rec1)
g.FillEllipse(bg2, rec)
rec.Size = PictureBox1.Image.Size
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] ng [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Graphics = Graphics.FromImage(bmp)
pth.AddString([/SIZE][SIZE=2][COLOR=#800000]"Welcome"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] FontFamily([/SIZE][SIZE=2][COLOR=#800000]"Arial"[/COLOR][/SIZE][SIZE=2]), [/SIZE][SIZE=2][COLOR=#0000ff]CInt[/COLOR][/SIZE][SIZE=2](FontStyle.Regular), 500, [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Point(370, 380), StringFormat.GenericTypographic)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] mx [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Drawing2D.Matrix(1.0F / 5, 0, 0, 1.0F / 5, -(1.0F / 5), -(1.0F / 5))
g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
g.Transform = mx
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] p [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Pen(Color.LightGray, 3)
g.DrawPath(p, pth)
g.FillPath(Brushes.Yellow, pth)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] mt [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Drawing2D.Matrix(1, 0, 0, 1, 50, 50)
g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(bmp, ClientRectangle, 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel)
g.FillPath(Brushes.Black, pth)
pth.Dispose()
PictureBox1.Image = bmp
PictureBox1.Refresh()
bmp.MakeTransparent(Color.White)
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]
[/COLOR][/SIZE]

 
Thanks! That works pretty well. It's a pretty basic GDI image, but I'm still learning, and I think it looks pretty good on my forums. Thanks for your help, and here is the final result.

welcome2.png
 
Back
Top