Я использую следующий код 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;
Вот результаты:
http://image.free.in.th/z/ie/yqbsg.png
Мне было интересно, почему шрифт ClearType выглядит так безобразно на ярком bg?(На bg, как темно-фиолетовый, вы не заметите черную рамку, но она все еще там)