类型为“ System.ArgumentException”的第一次机会异常发生在System.Drawing.dll中

乔瑞

我正在尝试进行全屏截屏并将其加载到pictureBox中,但这给了我这个错误:System.Drawing.dll中发生了类型'System.ArgumentException'的第一次机会异常。其他信息:Ongeldige参数。

码:

    using (Bitmap bmpScreenCapture = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                                                Screen.PrimaryScreen.Bounds.Height))
    {
        using (Graphics g = Graphics.FromImage(bmpScreenCapture))
        {
            g.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
                             Screen.PrimaryScreen.Bounds.Y,
                             0, 0,
                             bmpScreenCapture.Size,
                             CopyPixelOperation.SourceCopy);
        }

        pictureBox1.Image = bmpScreenCapture;
    }

乔莉。

迈克尔·刘

发生异常是因为该using语句在将位图分配给后处理了它pictureBox1.Image,因此PictureBox在需要重新绘制自身时无法显示位图:

using (Bitmap bmpScreenCapture = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                                            Screen.PrimaryScreen.Bounds.Height))
{
    // ...

    pictureBox1.Image = bmpScreenCapture;
} // <== bmpScreenCapture.Dispose() gets called here.

// Now pictureBox1.Image references an invalid Bitmap.

要解决此问题,请保留Bitmap变量声明和初始化程序,但删除以下代码using

Bitmap bmpScreenCapture = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                                     Screen.PrimaryScreen.Bounds.Height);

// ...

pictureBox1.Image = bmpScreenCapture;

您仍应确保最终处理完位图,但前提是您确实真正不再需要它时(例如,如果以后再替换pictureBox1.Image另一个位图)。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

类型'System.Data.Entity.Validation.DbEntityValidationException'的第一次机会异常发生在EntityFramework.dll中

来自分类Dev

mscorlib.dll中发生类型为“ System.ArgumentException”的第一次机会异常

来自分类Dev

类型'System.Data.Entity.Core.EntityCommandExecutionException'的第一次机会异常发生在EntityFramework.SqlServer.dll中

来自分类Dev

mscorlib.dll中发生类型为'System.OverflowException'的第一次机会异常

来自分类Dev

mscorlib.dll中发生类型为'System.FormatException'的第一次机会异常

来自分类Dev

PresentationFramework.dll中发生类型'System.Windows.Markup.XamlParseException'的第一次机会异常吗?

来自分类Dev

Quartz.Net,使用Unity for DI时在Unity.Mvc3.dll中发生类型为“ System.NullReferenceException”的第一次机会异常

来自分类Dev

'System.ArgumentException'发生在System.Drawing.dll中

来自分类Dev

网络Controller.exe中发生类型为'System.Runtime.InteropServices.SEHException'的第一次机会异常

来自分类Dev

在System.Drawing.dll中发生了'System.ArgumentException'类型的未处理异常,用于灰度

来自分类Dev

Lambda表达式导致“类型'System.NullReferenceException'的第一次机会异常”

来自分类Dev

Windows 窗体“System.Data.dll 中发生类型为‘System.ArgumentException’的未处理异常”

来自分类Dev

EntityFramework.dll中发生类型为'System.ArgumentException'的异常,但未在用户代码中处理

来自分类Dev

System.Web.Extensions.dll中发生类型为'System.InvalidOperationException'的异常,但未在用户代码中处理

来自分类Dev

MySql - System.Data.dll 中发生类型为“System.InvalidOperationException”的未处理异常

来自分类Dev

System.Data.dll中发生了'System.ArgumentException'类型的未处理异常

来自分类Dev

发生“ Microsoft.CSharp.RuntimeBinder.RuntimeBinderException”类型的第一次机会异常

来自分类Dev

BundleConfig类中的MVC错误:mscorlib.dll中发生了类型为'System.NullReferenceException'的异常

来自分类Dev

EntityFramework.dll中发生类型为'System.InvalidOperationException'的异常,但未在用户代码中处理

来自分类Dev

EntityFramework.dll中发生类型为'System.InvalidOperationException'的异常,但在注册时未在用户代码中处理

来自分类Dev

EntityFramework.SqlServer.dll中发生类型为'System.Reflection.TargetInvocationException'的异常,但未在用户代码中处理

来自分类Dev

“System.Data.SqlClient.SqlException”类型的异常发生在“System.Data.dll”中,但未在用户代码中处理

来自分类Dev

cms.dll中发生类型'System.ArgumentException'的异常,但未在用户代码中处理

来自分类Dev

System.Drawing.dll中的C#内存不足异常

来自分类Dev

使用protobuf将类型为System.Drawing.Rectangle的.Net序列化为C ++

来自分类Dev

创建类型为System.Drawing.Point的运行时对象时出错

来自分类Dev

关闭表单时,我在System.Windows.Forms.dll中发生类型为'System.ObjectDisposedException'的异常,但未在用户代码中处理

来自分类Dev

错误:System.Data.dll中发生了类型为'System.Data.SqlClient.SqlException'的异常,但未在用户代码中处理

来自分类Dev

在View中使用2个模块:System.Web.Mvc.dll中发生类型为'System.InvalidOperationException'的异常,但未在用户代码中处理

Related 相关文章

  1. 1

    类型'System.Data.Entity.Validation.DbEntityValidationException'的第一次机会异常发生在EntityFramework.dll中

  2. 2

    mscorlib.dll中发生类型为“ System.ArgumentException”的第一次机会异常

  3. 3

    类型'System.Data.Entity.Core.EntityCommandExecutionException'的第一次机会异常发生在EntityFramework.SqlServer.dll中

  4. 4

    mscorlib.dll中发生类型为'System.OverflowException'的第一次机会异常

  5. 5

    mscorlib.dll中发生类型为'System.FormatException'的第一次机会异常

  6. 6

    PresentationFramework.dll中发生类型'System.Windows.Markup.XamlParseException'的第一次机会异常吗?

  7. 7

    Quartz.Net,使用Unity for DI时在Unity.Mvc3.dll中发生类型为“ System.NullReferenceException”的第一次机会异常

  8. 8

    'System.ArgumentException'发生在System.Drawing.dll中

  9. 9

    网络Controller.exe中发生类型为'System.Runtime.InteropServices.SEHException'的第一次机会异常

  10. 10

    在System.Drawing.dll中发生了'System.ArgumentException'类型的未处理异常,用于灰度

  11. 11

    Lambda表达式导致“类型'System.NullReferenceException'的第一次机会异常”

  12. 12

    Windows 窗体“System.Data.dll 中发生类型为‘System.ArgumentException’的未处理异常”

  13. 13

    EntityFramework.dll中发生类型为'System.ArgumentException'的异常,但未在用户代码中处理

  14. 14

    System.Web.Extensions.dll中发生类型为'System.InvalidOperationException'的异常,但未在用户代码中处理

  15. 15

    MySql - System.Data.dll 中发生类型为“System.InvalidOperationException”的未处理异常

  16. 16

    System.Data.dll中发生了'System.ArgumentException'类型的未处理异常

  17. 17

    发生“ Microsoft.CSharp.RuntimeBinder.RuntimeBinderException”类型的第一次机会异常

  18. 18

    BundleConfig类中的MVC错误:mscorlib.dll中发生了类型为'System.NullReferenceException'的异常

  19. 19

    EntityFramework.dll中发生类型为'System.InvalidOperationException'的异常,但未在用户代码中处理

  20. 20

    EntityFramework.dll中发生类型为'System.InvalidOperationException'的异常,但在注册时未在用户代码中处理

  21. 21

    EntityFramework.SqlServer.dll中发生类型为'System.Reflection.TargetInvocationException'的异常,但未在用户代码中处理

  22. 22

    “System.Data.SqlClient.SqlException”类型的异常发生在“System.Data.dll”中,但未在用户代码中处理

  23. 23

    cms.dll中发生类型'System.ArgumentException'的异常,但未在用户代码中处理

  24. 24

    System.Drawing.dll中的C#内存不足异常

  25. 25

    使用protobuf将类型为System.Drawing.Rectangle的.Net序列化为C ++

  26. 26

    创建类型为System.Drawing.Point的运行时对象时出错

  27. 27

    关闭表单时,我在System.Windows.Forms.dll中发生类型为'System.ObjectDisposedException'的异常,但未在用户代码中处理

  28. 28

    错误:System.Data.dll中发生了类型为'System.Data.SqlClient.SqlException'的异常,但未在用户代码中处理

  29. 29

    在View中使用2个模块:System.Web.Mvc.dll中发生类型为'System.InvalidOperationException'的异常,但未在用户代码中处理

热门标签

归档