【问题标题】:string with surrounding color带有周围颜色的字符串
【发布时间】:2013-07-25 19:19:48
【问题描述】:

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

现在我首先使用

创建字符串
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

问题是大图需要很长时间

有更好的方法吗?

【问题讨论】:

  • 那么您在任务的哪一部分遇到了问题?您是在问如何实现isnabor 方法吗?
  • 大图需要很长时间,有什么更好的办法吗?

标签: vb.net string brushes


【解决方案1】:
【解决方案2】:

在我朋友的帮助下,我在这里找到了答案:

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

【讨论】:

    猜你喜欢
    • 2012-10-13
    • 2019-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-16
    • 1970-01-01
    • 1970-01-01
    • 2021-06-17
    相关资源
    最近更新 更多