周围颜色的字符串

时间:2013-07-25 18:20:22

标签: vb.net string brushes

我想在vb.net中制作一个字符串
的图像 它应该由2种颜色组成,一种是前色,另一种是围绕第一种颜色的颜色 我应该如何使用代码? 我的结果必须是这样的图像(黄色为前景色,红色为背景)
an image with 2 colors [字符串是波斯语]

现在我首先使用

制作字符串
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)

然后通过检查每个像素来处理这个图像,如果它们接近字符串我将它们染成红色,代码就是这个

        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

问题是大图像需要很长时间

更好的方法吗?

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:1)

在我朋友的帮助下,我发现答案是:

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