vb.netstringbrushes

string with surrounding color


i want to make an image in vb.net which is a string
it should be made of 2 colors one as forecolor the other as a color surrounding the first one
how should i make it using code?
my result must be some thing like this image(yellow as forecolor and red! as background)
an image with 2 colors [the string is in persian]

right now i first make the string using

Dim result As New Bitmap(100, 100)
Dim g As Graphics = Graphics.FromImage(result)
g.DrawString("My string", New Font("Arial", 40), New SolidBrush(Color.yellow), 22, 22)

and then process this image by checking every single pixel and if they are close to the string i color them as red , the code is this

        kr = font_color.R
        kg = font_color.G
        kb = font_color.B
For i = 0 To (img.Height - 1) Step 1
                prg.Value = prg.Value + 1
                For j = 0 To (img.Width - 1)
                    If (kr = img.GetPixel(j, i).R And kg = img.GetPixel(j, i).G And kb = img.GetPixel(j, i).B) Then
                   'some code
                    ElseIf (isnabor(j, i) = True) Then'checks if it is close enough or not
                        img.SetPixel(j, i, back_color)
                    Else
                        img.SetPixel(j, i, Color.Transparent)
                    End If
                Next
            Next

The problem is that it takes a long time for a large image

any better way?


Solution

  • Try using GraphicsPath. Check the following links for more information