GraphicsPath.AddString()中具有某些字体和字符的通用GDI +异常 [英] Generic GDI+ exception in GraphicsPath.AddString() with certain fonts and characters

查看:251
本文介绍了GraphicsPath.AddString()中具有某些字体和字符的通用GDI +异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么想法为什么最近的Windows更新之一会导致GraphicsPath.AddString()和某些字体出现问题,但仅适用于特定字符?该如何解决?

Any ideas why one of recent Windows updates causes issues with GraphicsPath.AddString() and some fonts but only for specific characters? How to fix that?

示例字体为薄铅笔手写(这是公共领域,因此您可以自己尝试).如果将Graphics.DrawString()与它配合使用,它将很好地工作.如果您尝试使用GraphicsPath.AddString()来写Lorem ipsum,它也可以正常工作,但是如果您尝试使用C字符(大写c)或5数字,它将失败.

Example font is Thin Pencil Handwriting (it's public domain, so you can try for yourself). It works fine if you use Graphics.DrawString() with it. It also works fine if you try to use GraphicsPath.AddString() with it to write Lorem ipsum, but will fail if you try to use C character (capital c) or 5 digit.

它在几周前运行良好,最近更新后,由于臭名昭著且几乎无法接受的通用GDI +例外情况,它不幸失败了.

It worked perfectly fine just few weeks ago and after recent updates it fails miserably with the infamous and virtually undebuggable 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()方法.

I'm using C# but I don't thing it's particularly C# related. Older machines without recent updates works fine, but I can't tell people not to install system updates :( I've also spotted two other fonts that cause similar issues - both with GraphicsPath.AddString() method.

推荐答案

今天早上安装更新后,我遇到了同样的问题.我发现最近发布的有关Microsoft的帖子似乎已解决了该问题,尽管该问题似乎仍然悬而未决.

I ran into the same issue after installing updates this morning. I found this recent post on Microsoft that seems to address it though the issue seems to still be outstanding.

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

这篇关于GraphicsPath.AddString()中具有某些字体和字符的通用GDI +异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆