Bitmap bmp = new Bitmap(300, 50);
Graphics gfx = Graphics.FromImage(bmp);
gfx.DrawString("Why I have black outer pixels?", new Font("Verdana", 14),
new SolidBrush(Color.White), 0, 0);
gfx.Dispose();
bmp.Save(Application.StartupPath + "\\test.png", ImageFormat.Png);
我需要文字完全是白色的。我尝试了不同的画笔,如Brushes.White等,但都不好。我能做什么?所有文本像素必须为白色,只是不透明度会发生变化。
最佳答案
解决:(结合使用textrenderinghints和拉绳)
Bitmap bmp = new Bitmap(300, 50);
Graphics gfx = Graphics.FromImage(bmp);
gfx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
gfx.DrawString("Why I have black outer pixels?", new Font("Verdana", 14),
new SolidBrush(Color.White), 0, 0);
gfx.Dispose();
bmp.Save(Application.StartupPath + "\\test.png", ImageFormat.Png);