【问题标题】:Invalid parameter when setting an image设置图像时参数无效
【发布时间】:2012-08-01 12:33:46
【问题描述】:

我在多台计算机上运行 .NET 2.0 程序。在一个我有这个错误反复发生,直到我重置应用程序。

 //line below was throwing the exception
 this.myButton.BackgroundImage = global::myNamespace.Properties.Resources.myImage;

例外:

 ExceptionType: ArgumentException
 Message: Parameter is not valid.
 Source: System.Drawing
 StackTrace:    at System.Drawing.Image.get_Flags()
     at System.Windows.Forms.ControlPaint.IsImageTransparent(Image backgroundImage)
      at System.Windows.Forms.Control.set_BackgroundImageLayout(ImageLayout value)

资源存在,重置后可以正常工作。任何人都可以提供任何关于可能发生的见解吗?

【问题讨论】:

  • 可能是图片文件被什么东西锁住了?病毒扫描程序浮现在脑海中......
  • 是的,同意...禁用杀毒软件
  • @CodingGorilla 如果我可以复制,我会尝试。

标签: c# winforms image exception-handling .net-2.0


【解决方案1】:

我建议您使用Process Monitor 来检查文件上的实时活动,以及哪些进程可能会锁定它。添加一个过滤器,其中路径是图像/资源文件的名称;这应该可以快速显示是否有任何东西在你背后的文件中胡闹。

【讨论】:

    【解决方案2】:

    是的,这是一个 6 年前的帖子!今天遇到了同样的错误,我花了比它应该的时间更长的时间来修复。我实际上是在启动时处理我的图像控件,所以我显然无法在运行时调整它的背景图像。如果你在这里,不妨仔细检查一下。

    【讨论】:

      猜你喜欢
      • 2018-12-18
      • 1970-01-01
      • 2013-06-01
      • 1970-01-01
      • 2014-07-14
      • 2012-09-07
      • 1970-01-01
      • 1970-01-01
      • 2016-08-15
      相关资源
      最近更新 更多