Question

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?

OTHER TIPS

by the help of my friend i found the answer here it is:

Dim result As New Bitmap(1000, 1000)
    Dim grp As Graphics = Graphics.FromImage(result)
    Dim gp As New Drawing2D.GraphicsPath
    Dim useFont As Font = New Font("IranNastaliq", 100, FontStyle.Regular)
    grp.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
    grp.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
    gp.AddString(rr.Lines(aa), useFont.FontFamily, FontStyle.Regular, 100, New Point(0, 0), StringFormat.GenericTypographic)
    useFont.Dispose()
    grp.FillPath(Brushes.White, gp)

    grp.DrawPath(Pens.Black, gp)

    gp.Dispose()
    pic.Image = result
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top