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

public static Bitmap GetPieWithText(String text, Color color, Color fontColor,Font font)
{
int size = ;
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(, , size-, size - ), , );
g.SmoothingMode = SmoothingMode.Default;
g.InterpolationMode = InterpolationMode.Default;
g.CompositingQuality = CompositingQuality.Default;
StringFormat stringFormat = new StringFormat();
stringFormat.Alignment = StringAlignment.Center;
if (text.ToString().Length == )
{
g.DrawString(text.ToString(), font, new SolidBrush(fontColor), new Rectangle(, , size-, size - ), stringFormat);
}
else
g.DrawString(text.ToString(), font, new SolidBrush(fontColor), new Rectangle(, , size - , size - ), stringFormat); return bmp;
}

首先使用以上代码解决,一直没有解决问题,后来调整了绘制区区域大小size解决了问题,供大家参考。

上一篇:zoj 1586


下一篇:Microsoft Tech Summit 2018 课程简述:利用 Windows 新特性开发出更好的手绘视频应用