DrawString
テキストを画像として書き込んでから90度回転させようとしています。ビットマップでも直接PictureBoxでも問題なく動作しますが、大きな違いは品質にあります。描かれたPictureBox
テキストは素晴らしい品質で見栄えがします。画像に描くと、ひどくブロック状に見えます。見栄えを良くするためにいくつかの変更を加えましたが、見た目が思ったほど良くありません。
サンプルコード:
Windowsフォームプロジェクトを使用し、その上に2つの画像ボックスとボタンを配置し、次のコードで実行して、意味を確認します。
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