该参数在System.Drawing.Bitmap..ctor( [英] Parameter is not valid at System.Drawing.Bitmap..ctor(

查看:597
本文介绍了该参数在System.Drawing.Bitmap..ctor(的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows应用程序,可以加载许多图像.最近我遇到了以下异常.我已经检查过我的代码在任何地方都没有使用ICON,而且每次仅在应用程序运行了至少半小时左右后,我才无法重新创建该错误.有身体可以帮忙吗?

I have an windows application which loads many images.recently i have been getting the below exception. I have checked my code am not using ICON anywhere also i am unable to recreate the error evertime it happens only after the application has run for atleast half hour or so. Can any body help?

at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)
   at System.Drawing.Bitmap..ctor(Int32 width, Int32 height)
   at System.Drawing.Icon.ToBitmap()
   at System.Windows.Forms.ThreadExceptionDialog..ctor(Exception t)
   at System.Windows.Forms.Application.ThreadContext.OnThreadException(Exception t)
   at System.Windows.Forms.Control.WndProcException(Exception e)
   at System.Windows.Forms.Control.ControlNativeWindow.OnThreadException(Exception e)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at IZZone.Program.Main()

推荐答案

最可能的原因是宽度或高度为负.

[更新]

好吧,在阅读您的更新后,在我看来您没有释放未使用的GDI句柄.您得到的错误是任意的(而不是您的用户代码).我相信,当Windows尝试重新绘制应用程序图标时,碰巧它达到了GDI句柄限制,这会导致一些GDI调用失败,因此,当Icon.ToBitmap调用Bitmap ctor时,许多或所有参数都是无效的(除非您具有用于调试的公共符号,否则您将看不到此内容.

因此,下一步是仔细检查所有图像对象处理完后是否正确处理.
Most likely cause is that either width or height is negative.

[Update]

Okay, having read your update it seems to me that you are not releasing unused GDI handles. The error you get is kinda arbitrary (and not from your user code). I believe that when Windows tries to repaint the app icon, coincidentally it hits the GDI handle limit, which results in some failed GDI calls, so by the time Icon.ToBitmap calls the Bitmap ctor, many or all the arguments are invalid (you cannot see this unless you have the public symbols for debugging).

So your next step is to double check if you are properly disposing off all your image objects after they are done with.


This[^] thread may provide a solution to you.


这篇关于该参数在System.Drawing.Bitmap..ctor(的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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