当我尝试渲染一个中文string像试标记好不好Graphics.DrawString绘制它
即使我将字体链接改为SimSun。 另一方面TextRenderer工作,但是当使用粗体字体时,它不能呈现可读的string。 似乎没有正确的方法来呈现粗体string。
这个问题在这里更详细的描述。 我做错了什么或Windows不支持在UI中的一些粗体string专业的本地化应用程序?
重现问题的代码是用于两个PictureBox的Windows窗体应用程序:
const string combined = "testing标记好不好This is a aber long"; private void cFontSize_ValueChanged(object sender, EventArgs e) { Bitmap bmp = new Bitmap(750, 140); Font f = new Font("Arial", (float)cFontSize.Value, IsBold ? FontStyle.Bold : FontStyle.Regular); using (var g = Graphics.FromImage(bmp)) { g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver; // Rendering with a Background Color solves the issue but // this would produce boxes of white or black color in the displayed image which looks even worse TextRenderer.DrawText(g, combined, f, new Point(0, 0), FontColor); } cPictureBox.Image = bmp; Bitmap bmp2 = new Bitmap(750, 140); using (var g = Graphics.FromImage(bmp2)) { g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver; g.DrawString(combined, f, FontBrush, 0, 0); } cPicture2.Image = bmp2; }
更新1:
当我添加为HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion \ FontLink \ SystemLink的字体链接设置
Arial Bold SIMSUNB.TTC,SimSun Bold MSGOTHIC.TTC,MS UI Gothic
那么Graphics.DrawString现在看起来确定althogh TextRender现在得到问题。 现在重新启动应用程序后,两个输出看起来都是字体好的,尽pipeTextRenderer仍然存在由于黑色反锯齿而使得粗体字变得不可读的问题。 我将重新启动机器检查任何caching效果。