GdiPlus 溢出异常

3

最近我在使用第三方工具时遇到了一个GDI+的OverflowException问题,这给我带来了一些麻烦。我正在努力找出问题的原因,并决定是否有任何解决该问题的方法。

错误发生在SafeNativeMethods.Gdip.GdipFillPath()中,返回的错误代码为11,等于GpStatus.ValueOverflow。我不知道这意味着什么,或者可能是什么原因导致的。后果相当严重,因为有一个大屏幕区域无法绘制。

此错误的堆栈跟踪如下:

System.OverflowException: 溢出错误。 at System.Drawing.Graphics.CheckErrorStatus(Int32 status) at System.Drawing.Graphics.FillPath(Brush brush, GraphicsPath path) at Northwoods.Go.GoShape.DrawPath(Graphics g, GoView view, Pen pen, Brush brush, GraphicsPath path) at Northwoods.Go.GoRoundedRectangle.Paint(Graphics g, GoView view) at Northwoods.Go.GoLayer.Paint(Graphics g, GoView view, RectangleF clipRect) at Northwoods.Go.GoView.PaintObjects(Boolean doc, Boolean view, Graphics g, RectangleF clipRect) at Northwoods.Go.GoView.PaintView(Graphics g, RectangleF clipRect) at Northwoods.Go.GoView.onPaintCanvas(PaintEventArgs evt) at Northwoods.Go.GoView.OnPaint(PaintEventArgs evt) at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs) at System.Windows.Forms.Control.WmPaint(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

显然这里使用了两个参数,其中GraphicsPath我无法控制,而Brush则由静态方法返回,为确保它不会被Dispose而导致问题,我尝试将Brush属性更改为像以下代码一样返回一个克隆对象。但是似乎没有任何影响。

public Brush 
{
   get {
         return MappingLinearGradient(this.Bounds).Clone();
       }
}
1个回答

3

据我所知,一个 Graphics 对象的最大平面面积是 (1 << 24) - 1 => 1670 万像素。

我不确定这个面积本身是否有限制,但建议您深入了解一下。


谢谢leppie。看起来不幸的是,我们在继续重新计算一些更正常的东西之前,将边界设置为了一个非常大的值。但有时,在这个工具内部的绘图线程获取这些新的边界之前,它的高度还没有被正确地计算出来...显然,float.MaxValue对于Graphics对象来说有点太大了。 - Ian

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接