在 GDI+ “参数无效。”设置pen.Width
我有一个System.Drawing.Pen _pen
。
当在某些迭代中设置 _pen.Width = 3
时,它会给我:
System.ArgumentException
Message="Parameter is not valid."
Source="System.Drawing" - System.Drawing.dll
StackTrace:
at System.Drawing.Pen.set_Width(Single value)
at MyProject.ctlPanneauGraphique.CustomLine.set_BorderWidth(Int32 value) in
....
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at MySolution.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
什么以及为什么?
I have a System.Drawing.Pen _pen
.
When in some iterations is setting _pen.Width = 3
it gives me:
System.ArgumentException
Message="Parameter is not valid."
Source="System.Drawing" - System.Drawing.dll
StackTrace:
at System.Drawing.Pen.set_Width(Single value)
at MyProject.ctlPanneauGraphique.CustomLine.set_BorderWidth(Int32 value) in
....
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at MySolution.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
What and why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您正在处理 _pen 变量吗?
如果不是,这可能表明存在资源泄漏问题,正如您所怀疑的那样。
如果是,这可能表明您正在访问已处置的实例。 GDI 对象在被释放后使用时通常会抛出 ArgumentException。
Are you disposing the _pen variable?
If not, this may indicate a resource leak problem as you have suspected.
If yes, this may indicate that you are accessing a disposed instance. GDI objects often throw ArgumentException when used after they have been disposed.
您如何初始化 _pen 变量?根据 MSDN 文档,如果您是使用 Pens 类来初始化变量,您将得到一个不可变的 Pen,其 Width 参数无法设置。尝试这样做将导致抛出 ArgumentException,这正是您所看到的。
How are you initializing the _pen variable? According to MSDN documentation, if you are using the Pens class to initialize your variable, you will get an immutable Pen, whose Width parameter cannot be set. Attempting to do so will result in an ArgumentException being thrown, which is exactly what you are seeing.
我开始认为这是由于内存泄漏问题造成的。显然,操作系统无法创建超过 10.000 个 GDI+ 对象...
在执行一些分析后,我检测到应用程序中存在巨大的内存泄漏,因此错误来自那里。
I started supposing that comes from a memory leak problem. Apparently the OS cant create more that 10.000 GDI+ objects...
After some analysis was performed I detected a huge memory leack in the application, so the error came from there.