c# - GdiPlus 溢出异常

标签 c# gdi+

我最近在 GDI+ 中通过第 3 方工具遇到了 OverflowException,这给我带来了一些问题。我正在尝试找出造成这种情况的原因,然后决定是否有解决问题的方法。

错误发生在 SafeNativeMethods.Gdip.GdipFillPath() 中,返回错误代码 11,等于 GpStatus.ValueOverflow。我不知道这意味着什么,也不知道是什么原因造成的。后果相当严重,因为我有大面积的屏幕无法绘制。

此错误的堆栈跟踪是:

System.OverflowException:溢出错误。 在 System.Drawing.Graphics.CheckErrorStatus(Int32 状态) 在System.Drawing.Graphics.FillPath(Brush笔刷,GraphicsPath路径) 在 Northwoods.Go.GoShape.DrawPath(Graphics g, GoView view, Pen pen, Brush 笔刷, GraphicsPath 路径) 在 Northwoods.Go.GoRoundedRectangle.Paint(图形 g,GoView View ) 在 Northwoods.Go.GoLayer.Paint(图形 g,GoView View ,RectangleF clipRect) 在 Northwoods.Go.GoView.PaintObjects( bool 文档、 bool View 、图形 g、RectangleF clipRect) 在 Northwoods.Go.GoView.PaintView(图形 g,RectangleF clipRect) 在 Northwoods.Go.GoView.onPaintCanvas(PaintEventArgs 事件) 在 Northwoods.Go.GoView.OnPaint(PaintEventArgs 事件) 在 System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e,Int16 层, bool disposeEventArgs) 在 System.Windows.Forms.Control.WmPaint(Message& m) 在 System.Windows.Forms.Control.WndProc(Message& m) 在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)

这里显然使用了 2 个参数。我无法控制的 GraphicsPath 和 Brush。画笔由静态方法返回,只是为了确保处理它不是问题,我尝试更改 Brush 属性以返回如下所示的克隆。然而,这似乎没有任何影响。

public Brush 
{
   get {
         return MappingLinearGradient(this.Bounds).Clone();
       }
}

最佳答案

IIRC,Graphics 对象的最大平面面积为 (1 << 24) - 1 => 1670 万像素。

我不确定该区域本身是否有限制,但我会调查一下。

关于c# - GdiPlus 溢出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/893069/

相关文章:

c# - ASP.NET/C# : DropDownList SelectedIndexChanged in server control not firing

.net - GDI + .NET : LinearGradientBrush wider than 202 pixels causes color wrap-around

.net - 设置字体真的有多重要?

.net - 椭圆绘图 WPF 动画

windows - 通用纯文本打印机驱动程序不起作用

c# - 将评论框脚本编辑为动态

c# - 如何使用 LINQ - Entity Framework 从表中选择存在于联结表中的元素

c# - 计算 linq 查询中的总计

c# - jQuery 模态弹出窗口不获取单击处理程序中的值

c# - 使用自定义 TTF 字体进行 DrawString 图像渲染