最近我在使用第三方工具时遇到了一个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();
}
}