1. 程式人生 > >C#一例繪制字體不清晰的解決辦法

C#一例繪制字體不清晰的解決辦法

graphics SM pub post static smooth bic pre clas

public static Bitmap GetPieWithText(String text, Color color, Color fontColor,Font font)
{
    int size = 22;
    Bitmap bmp = new Bitmap(size, size);
    Graphics g = Graphics.FromImage(bmp);
    g.SmoothingMode = SmoothingMode.AntiAlias; //使繪圖質量最高,即消除鋸齒
    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
    g.CompositingQuality 
= CompositingQuality.HighQuality; g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; g.FillPie(new SolidBrush(color), new Rectangle(0, 0, size-1, size - 1), 0, 360); g.SmoothingMode = SmoothingMode.Default; g.InterpolationMode = InterpolationMode.Default; g.CompositingQuality
= CompositingQuality.Default; StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Center; if (text.ToString().Length == 2) { g.DrawString(text.ToString(), font, new SolidBrush(fontColor), new Rectangle(0, 0, size-1, size - 1), stringFormat); }
else g.DrawString(text.ToString(), font, new SolidBrush(fontColor), new Rectangle(0, 0, size - 1, size - 1), stringFormat); return bmp; }

首先使用以上代碼解決,一直沒有解決問題,後來調整了繪制區區域大小size解決了問題,供大家參考。

C#一例繪制字體不清晰的解決辦法