簡體   English   中英

帶周圍顏色的字符串

[英]string with surrounding color

我想在 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

問題是大圖需要很長時間

有什么更好的方法嗎?

在我朋友的幫助下,我在這里找到了答案:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM