gpt4 book ai didi

c# - 具有某些字体和字符的 GraphicsPath.AddString() 中的通用 GDI+ 异常

转载 作者:太空宇宙 更新时间:2023-11-03 10:30:43 30 4
gpt4 key购买 nike

知道为什么最近的 Windows 更新之一会导致 GraphicsPath.AddString() 和某些字体出现问题但仅限于特定字符吗?如何解决?

示例字体为 Thin Pencil Handwriting (这是公共(public)领域,因此您可以自己尝试)。如果您将 Graphics.DrawString() 与它一起使用,它会很好地工作。如果您尝试使用 GraphicsPath.AddString() 来编写 Lorem ipsum,它也能正常工作,但如果您尝试使用 C,它将失败> 字符(大写 c)或 5 数字。

它在几周前工作得很好,在最近的更新之后,它因臭名昭著且几乎无法调试的 Generic GDI+ exception 而悲惨地失败了。

示例代码:

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() 方法.

最佳答案

我今天早上安装更新后遇到了同样的问题。我发现这篇最近关于 Microsoft 的帖子似乎解决了这个问题,尽管这个问题似乎仍然悬而未决。

https://connect.microsoft.com/VisualStudio/feedback/details/1331855/kb3045171-crash-gdi-with-system-drawing-drawing2d-addstring

关于c# - 具有某些字体和字符的 GraphicsPath.AddString() 中的通用 GDI+ 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30346758/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com