1
我有以下的C#代碼來獲得在Windows 7從位圖圖形的64位抗鋸齒文本不抗鋸齒和的ClearType文本在窗口非常難看形成
protected Graphics GetImageGraphics()
{
var g = Graphics.FromImage(image);
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
g.FillRectangle(backBrush, new Rectangle(Point.Empty, Bounds.Size));
return g;
}
這是用來如下:
g.DrawImageUnscaled(image, Bounds);
所得到的文本爲v:
protected override void Redraw()
{
var g = GetImageGraphics();
var path = RoundedRectanglePath(shapeRect, CornerRadius);
g.FillPath(selected ? selectedBrush : brush, path);
g.DrawPath(pen, path);
foreach(var pin in pins)
pin.Value.Render(g);
var labelMax = shapeRect;
labelMax.Inflate(-10, -10);
var fmt = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.WordBreak | TextFormatFlags.WordEllipsis;
TextRenderer.DrawText(g, Task.Symbol.Label, Font, labelMax, Color.Black, fmt);
fmt = TextFormatFlags.Left | TextFormatFlags.Top | TextFormatFlags.SingleLine | TextFormatFlags.WordEllipsis;
TextRenderer.DrawText(g, Task.TaskId, Font, idRect, Color.Black, fmt);
}
創建的圖像,然後使用拷貝到屏幕醜陋。如果我將TextRenderingHint更改爲AntiAlias或AntiAliasGridFit,則字體呈現得更清晰,但沒有顯示任何抗鋸齒(如SingleBitPerPixel)
我在做什麼錯?
您必須繪製背景以進行消除鋸齒工作。例如,添加g.Clear(Color.White)。 –