【发布时间】:2011-11-20 18:19:33
【问题描述】:
我正在使用以下 C# 代码制作一张带有文字的图片
// Create font. Parameter is a global variable
Font objFont = new Font(fontname, fontsize, fontstyle, System.Drawing.GraphicsUnit.Pixel);
// Grab an existing image from picture box. (target is picturebox's name)
Bitmap result;
if (target.Image != null)
{
result = new Bitmap(target.Image);
}
else
{
result = new Bitmap(target.Width, target.Height);
}
Graphics objGraphics = Graphics.FromImage(result);
// And draw to it. Select a mode with check box.
objGraphics.SmoothingMode = SmoothingMode.HighQuality;
if (!checkBox1.Checked)
{
objGraphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
}
else
{
objGraphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
}
Brush b = new LinearGradientBrush(new Rectangle(new Point(x, y), objGraphics.MeasureString(text, objFont).ToSize()),color1,color2,LinearGradientMode.Vertical);
objGraphics.DrawString(text, objFont, b, x, y);
objGraphics.Save();
//Set the result to picturebox
target.Image = result;
objGraphics.Dispose();
b.Dispose();
在此代码之前,target.BackColor 已设置为所需的颜色,例如
target.BackColor = Color.Black;
这是结果:
(来源:free.in.th)
我想知道为什么 ClearType 字体在明亮的背景上看起来如此丑陋? (在像深紫色这样的背景上,您不会注意到黑色边框,但它仍然存在)
【问题讨论】:
-
GDI 和 ClearType 在 WinForms 应用程序中不能很好地混合(假设您使用的是 WinForms,因为它是 System.Drawing)。
标签: c# fonts system.drawing cleartype