縁取り文字を描く

System.Drawing.Drawing2D.GraphicsPath を用いると、縁取り文字を描くことができます。 DrawPathで縁を、FillPath で内側を描画できます。 LinearGradientBrush などと組み合わせると視覚効果の高いテキストを描けます。以下はこの例です。


■ 処理コード
string text = "こんにちは !";
Bitmap bitmap = new Bitmap(400, 80);
Graphics g = Graphics.FromImage(bitmap);
g.SmoothingMode = SmoothingMode.AntiAlias;
GraphicsPath path = new GraphicsPath();
path.AddString(text, new FontFamily("メイリオ"), (int)FontStyle.Bold, 64, new Point(0, 0), StringFormat.GenericTypographic);
LinearGradientBrush innerBrush = new LinearGradientBrush(new Point(0, 0), new Point(400, 0), Color.Red, Color.Blue);
ColorBlend colorBlend = new ColorBlend(3);
Color[] colors = { Color.Red, Color.Green, Color.Blue };
float[] positions = { 0.0f, 0.5f, 1.0f };
colorBlend.Colors = colors;
colorBlend.Positions = positions;
innerBrush.InterpolationColors = colorBlend;
g.FillPath(innerBrush, path);
g.DrawPath(new Pen(Brushes.Black, 2), path);
g.Dispose();
pictureBox.Image = bitmap;