我对图形编程很陌生,更不用说VB了,所以我在这里碰壁了。我基本上已经完成了所有我所缺少的代码,只是在图像周围添加了一些透明填充/边框像素,但我被卡住了。我环顾四周,但我看到的示例似乎非常复杂,在我看来就像是矫枉过正(一页一页的代码)。
任何指针或易于理解的教程/示例将不胜感激。
在下面附加了当前代码:
当前代码
Dim img As Image = New Bitmap(100, 100)
Dim Drawing As Graphics = Graphics.FromImage(img)
Dim rand As New Random
Dim bgcolor As Color = Color.FromArgb(rand.Next(64, 196), rand.Next(64, 196), rand.Next(64, 196))
Dim family As FontFamily = Nothing
Dim fontName As String = "Lucida Sans Typewriter"
Dim fontSize As Single = 42
Using fontTester As New Font(fontName, fontSize, FontStyle.Regular, GraphicsUnit.Pixel)
If fontTester.Name = fontName Then
family = New FontFamily("Lucida Sans Typewriter")
Else
Try
Dim privateFonts As New System.Drawing.Text.PrivateFontCollection()
privateFonts.AddFontFile(HttpContext.Current.Server.MapPath("~/") + "\styles\fonts\LTYPE.ttf")
Dim font As New System.Drawing.Font(privateFonts.Families(0), 42)
family = font.FontFamily
Catch ex As Exception
family = New FontFamily("Arial")
End Try
End If
End Using
Dim FontText As Font = New Font(family, 42, FontStyle.Regular)
Drawing.Clear(bgcolor)
Dim textBrush As Brush = New SolidBrush(Color.White)
Drawing.DrawString(initials, FontText, textBrush, 7, 16)
Drawing.Save()
textBrush.Dispose()
Drawing.Dispose()