我使用下面的C#代碼,以使圖片與文本在它爲什麼System.Drawing + ClearType字體有醜陋的黑色碎片?
// 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;
這是結果:
http://image.free.in.th/z/ie/yqbsg.png
我想知道這是爲什麼ClearType字體看起來明亮的BG這麼難看? (在BG像暗紫色,你不會注意到黑色邊框,但它仍然存在)
GDI和ClearType在WinForms應用程序中混合不好(假設您使用WinForms,因爲它是System.Drawing)。 – BoltClock