C#一例绘制字体不清晰的解决办法

2021-04-19 08:29

阅读:352

标签:graph   mode   bit   with   graphics   from   dbr   idf   ring   

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#一例绘制字体不清晰的解决办法

标签:graph   mode   bit   with   graphics   from   dbr   idf   ring   

原文地址:https://www.cnblogs.com/zhaogaojian/p/8668695.html


评论


亲,登录后才可以留言!