最近需要用GDI+绘制文字可是效果不理想,小字很模糊。望大侠帮忙。
很是纠结啊,SIZE低于16的字一塌糊涂。
Module ModuleFontsgdi+ vb2008 vb.net
Function GDI文字倒影(ByVal mytext As String, ByVal textFont As Font, ByVal textColor As Color) As Bitmap
Dim bmp_t_size As New Bitmap(10, 10)
Dim date_g As Graphics = Graphics.FromImage(bmp_t_size)
Dim textSize As SizeF = date_g.MeasureString(mytext, textFont)
Dim size As Size = New Size(Math.Truncate(textSize.Width) + 1, Math.Truncate(textSize.Height) + 1)
Dim myBrush As Brush = New SolidBrush(System.Drawing.Color.FromArgb(textColor.A, textColor.R, textColor.G, textColor.B))
Dim bmp_dy As Bitmap = New Bitmap(size.Width, size.Height)
Dim g As Graphics = Graphics.FromImage(bmp_dy)
'''' 为何这些开启也不能消除锯齿
'g.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
'g.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
g.DrawString(mytext, textFont, myBrush, 0, 0)
bmp_dy.RotateFlip(RotateFlipType.Rotate180FlipX)
Dim px As Color
Dim ap As Integer = 0
For x = 0 To size.Width - 1
For y = 0 To size.Height - 1
px = bmp_dy.GetPixel(x, y)
If px.A Then
If y Then
ap = CInt(textColor.A * 0.4 - y * (textColor.A * 0.4 / size.Height))
Else
ap = 0
End If
bmp_dy.SetPixel(x, y, Color.FromArgb(ap, px.R, px.G, px.B))
End If
Next
Next
Dim bmp As Bitmap = New Bitmap(size.Width, CInt(size.Height + textFont.Size))
g = Graphics.FromImage(bmp)
g.DrawString(mytext, textFont, myBrush, 0, 0)
'Dim BRS As Brush = New System.Drawing.Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(0, 1), Color.FromArgb(255, 0, 0, 0), Color.FromArgb(50, 0, 0, 0))
'g.DrawString(mytext, textFont, BRS, New RectangleF(0, 0, bmp.Width + textFont.Height, bmp.Height + textFont.Height))
'g.DrawString(mytext, textFont, BRS, New RectangleF(1, 1, bmp.Width + textFont.Height, bmp.Height + textFont.Height))
'g.DrawString(mytext, textFont, BRS, New RectangleF(0, 1, bmp.Width + textFont.Height, bmp.Height + textFont.Height))
'g.DrawString(mytext, textFont, BRS, New RectangleF(1, 0, bmp.Width + textFont.Height, bmp.Height + textFont.Height))
'g.DrawString(mytext, textFont, BRS, New RectangleF(0, 0.5, bmp.Width + textFont.Height, bmp.Height + textFont.Height))
'g.DrawString(mytext, textFont, BRS, New RectangleF(0.5, 0, bmp.Width + textFont.Height, bmp.Height + textFont.Height))
'g.DrawString(mytext, textFont, myBrush, 0.5, 0.5)
Dim rf As RectangleF = New RectangleF(0, textFont.SizeInPoints, bmp_dy.Width, bmp_dy.Height)
g.DrawImage(bmp_dy, rf)
'Dim bmp1 As Bitmap = bmp.Clone
'g.Clear(Color.FromArgb(0, 0, 0, 0))
'g.DrawImage(bmp1, New Rectangle(0, 0, bmp.Width / 8, bmp.Height / 8), 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel)
Return bmp
End Function
End Module
[解决办法]
不错不错