在System.Drawing.dll中添加不带System.InvalidCastException的位图 [英] Add Bitmap without System.InvalidCastException in System.Drawing.dll

查看:83
本文介绍了在System.Drawing.dll中添加不带System.InvalidCastException的位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在带有CE6.0的移动设备上运行以下代码行

在图片框中正确显示了位图.
我也尝试了具有相同结果的jpg和png格式.

如果我激活,调试器仅在异常处停止.
调试->公共语言运行时->系统-> System.InvalidCastException
没有此功能,它将仅在输出"窗口中将其显示为异常(第一次机会),并且代码将按预期运行.


有人知道如何防止这种异常或如何找到这种异常的原因吗?


Hi,

i run the following lines of code on a Mobile Device with CE6.0

The Bitmap is shown proper in the Picturebox.
I tried also jpg and png Format with same Result.

The Debugger stops only at the Exception if i activate.
Debugging->Common Language Runtime-> System -> System.InvalidCastException
Without this it will Show it only as Exception (first Chance) in the Output window and the code runs like expected.


Does anybody know how to prevent against this Exception or how to find the reason for it?


try
{
  System.Windows.Forms.PictureBox picturebox = new System.Windows.Forms.PictureBox();
 
  // this line causes the InvalidCastExeption
  // the Bitmap is available and shown proper in the Picturebox.
  // the Debugger stop only in this line if i activate
  // Debugging->Common Language Runtime-> System -> System.InvalidCastException
  // but it jumps over the two catch blocks
  picturebox.Image = new System.Drawing.Bitmap("Bitmap.bmp");
 
  this.Form1.Controls.Add(picturebox);
}
catch (System.InvalidCastException ice)
{
  System.Console.WriteLine(ice.Message);
}
catch (System.Exception ex)
{
  System.Console.WriteLine(ex.Message);
}



谢谢的
de-kekse



thank''s
de-kekse

推荐答案

您不必担心输出窗口中的第一次机会异常".这是在框架代码中引发并捕获的异常.

由于您的代码按预期运行,因此您可以放心地忽略第一个机会异常.
A "first chance exception" in the output window is not something you need to worry about. It''s an exception which has been thrown and caught within the framework code.

Since your code is running as expected, you can safely ignore the first-chance exception.


这篇关于在System.Drawing.dll中添加不带System.InvalidCastException的位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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