다음 코드를 사용하여 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