Graphics.Drawstring在PictureBox中看起来不错,但在位图中却很糟糕 [英] Graphics.Drawstring looks nice in PictureBox but horrible in a Bitmap
问题描述
我正在尝试使用 DrawString
将文本写为图像,然后将其旋转90度.无论是位图还是直接在PictureBox上都可以正常工作,但是最大的区别在于质量.绘制的 PictureBox
文本质量很好,外观也很好.当我将其绘制在图像上时,它看起来很可怕而且很块状.我进行了一些更改以尝试使其看起来更好,但它看起来并不尽如人意.
I am trying to use DrawString
to write text as an image and then rotate it 90 degrees. It works fine with both a bitmap or directly on a PictureBox, but the big difference is in the quality. The PictureBox
text drawn has great quality and looks nice. When I draw it on an image it looks horrible and blocky. I've made a few changes to try and get it to look nicer, but it doesn't look nearly as nice as it should.
示例代码:
使用Windows Forms项目并在其上放置2个图片框和一个按钮,并使用以下代码运行它以查看我的意思:
Use a Windows Forms project and place 2 picture boxes on it and a button and run it with the following code to see what I mean:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim g As System.Drawing.Graphics
g = PictureBox1.CreateGraphics
' x.DrawRectangle(New Pen(Brushes.White, 200), New Rectangle(0, 0, 200, 200))
g.TranslateTransform(10.0F, 0.0F)
g.RotateTransform(90)
g.DrawString("MM Components", New Font("Arial", 7, FontStyle.Regular), Brushes.DarkBlue, New PointF(0, 0))
Dim g2 As System.Drawing.Graphics
Dim img As New Bitmap(300, 300, Drawing.Imaging.PixelFormat.Format24bppRgb)
g2 = Graphics.FromImage(img)
g2.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
g2.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAliasGridFit
g2.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
' img.SetResolution(150, 150)
' x.DrawRectangle(New Pen(Brushes.White, 200), New Rectangle(0, 0, 200, 200))
g2.TranslateTransform(10.0F, 0.0F)
g2.RotateTransform(90)
g2.FillRectangle(Brushes.White, 0, 0, 300, 300)
g2.DrawString("MM Components", New Font("Arial", 7, FontStyle.Regular), Brushes.DarkBlue, New PointF(0, 0))
PictureBox2.Image = img
'System.Threading.Thread.Sleep(20)
End Sub
End Class
推荐答案
这些更改似乎使它看起来不错....
These changes seem to make it look nice....
g2.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
g2.TextRenderingHint = Drawing.Text.TextRenderingHint.ClearTypeGridFit
g2.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
这篇关于Graphics.Drawstring在PictureBox中看起来不错,但在位图中却很糟糕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!