您知道为什么最近的 Windows 更新之一会导致 GraphicsPath.AddString()
和某些字体出现问题,但仅针对特定字符吗?如何解决这个问题?
示例字体为Thin Pencil Handwriting (这是公共(public)领域,所以你可以自己尝试)。如果您将 Graphics.DrawString() 与它一起使用,它就可以正常工作。如果您尝试使用 GraphicsPath.AddString()
来编写 Lorem ipsum
,它也可以正常工作,但如果您尝试使用 C
则会失败> 字符(大写 c
)或 5
数字。
就在几周前,它还工作得很好,但在最近的更新之后,它因臭名昭著且几乎无法调试的通用 GDI+ 异常而惨遭失败。
示例代码:
string textOK = "Lorem ipsum";
string broken = "C"; // Yes, only capital letter 'c'!
FontStyle style = FontStyle.Regular;
Bitmap b = new Bitmap(200, 200, PixelFormat.Format32bppPArgb)
using (Graphics g = Graphics.FromImage(b))
{
g.Clear(Color.White);
g.SmoothingMode = SmoothingMode.HighQuality;
using (StringFormat sf = new StringFormat())
{
RectangleF rect = new RectangleF(0, 0, 200, 200);
float size = 8;
using (Font f = new System.Drawing.Font("Thin Pencil Handwriting", size, style))
{
// Works perfectly fine
g.DrawString(textOK, f, Brushes.Black, rect, sf);
g.DrawString(broken, f, Brushes.Black, rect, sf);
}
using (GraphicsPath path = new GraphicsPath())
{
FontFamily family = new FontFamily("Thin Pencil Handwriting");
// This works fine
path.AddString(textOK, family, (int)style, size, rect, sf);
// This causes Generic GDI+ exception!
path.AddString(broken, family, (int)style, size, rect, sf);
g.FillPath(Brushes.Black, path);
}
}
}
我正在使用 C#,但我不认为它与 C# 特别相关。没有最近更新的旧机器工作正常,但我不能告诉人们不要安装系统更新:(我还发现了其他两种导致类似问题的字体 - 都使用 GraphicsPath.AddString()
方法.
最佳答案
今天早上安装更新后,我遇到了同样的问题。我发现微软最近发布的这篇文章似乎解决了这个问题,尽管这个问题似乎仍然悬而未决。
关于c# - GraphicsPath.AddString() 中具有某些字体和字符的通用 GDI+ 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30346758/