我在Bitmap变量上收到错误消息“参数无效”,无法找出原因

时间:2011-09-08 22:10:41

标签: c# error-handling

form1 中,我想检查比较是否为真,并在messagebox和我的日志文件中显示。

if (ImagesComparion1.ImageComparison(File1, file2, image_scan_text_rect) == true)
                                             {

代码继续......

然后在它将文件复制到新位置之前的底部我想检查它是否在ImageComparion1.ImageComparison(File1,file2,image_scan_text_rect返回true或false)时复制文件。

所以我做了:

bool testComparison = ImagesComparion1.ImageComparison(File1, file2, image_scan_text_rect);
                                            MessageBox.Show("testComparison ImageComparison returned " + testComparison);
                                            Logger.Write("testComparison ImageComparison returned " + testComparison);

我用bool来判断它是真还是假。

但是当它到达线bool testComparison = ImagesComparion1.ImageComparison(File1,file2,image_scan_text_rect);  并输入类和函数ImagesComparion1.ImageComparison我收到错误消息说“参数无效”

所以我在这行bool上使用断点testComparison = ImagesComparion1.ImageComparison(File1,file2,image_scan_text_rect);  并看到它进入ImagesComparion1.ImageComparison:

public bool ImageComparison(Bitmap Image1, Bitmap Image2, Rectangle Rect)
        {
            Logger.Write("Rect >>>> " + Rect.ToString());

            int x;
            int y;
            bool different = false;
            textbox3 = Rect.ToString();
            //if pictures are not of same size, return that they are different
            if (Image1.Width != Image2.Width || Image1.Height != Image2.Height)
            {

在线上如果(Image1.Width!= Image2.Width || Image1.Height!= Image2.Height)错误即将出现。

这是一个例外:

System.ArgumentException was unhandled by user code
   Message=Parameter is not valid.
   Source=System.Drawing
   StackTrace:
        at System.Drawing.Image.get_Width()
        at WindowsFormsApplication1.ImagesComparison.ImageComparison(Bitmap Image1, Bitmap Image2, Rectangle Rect) in D:\C-Sharp\Download File\Downloading-File-Project-Version-012\Downloading File\ImagesComparison.cs:line 50
        at WindowsFormsApplication1.Form1.Client_DownloadFileCompleted(Object sender, AsyncCompletedEventArgs e) in D:\C-Sharp\Download File\Downloading-File-Project-Version-012\Downloading File\Form1.cs:line 1769
   InnerException:

ImagesComparison.cs中的第50行是:if(Image1.Width!= Image2.Width || Image1.Height!= Image2.Height)错误来自哪里。

Form1.cs中的第1769行是:bool testComparison = ImagesComparion1.ImageComparison(File1,file2,image_scan_text_rect);

我不知道为什么它会在这条线上给我错误。我想要的只是得到一个bool变量,以便能够知道它的真或假。

感谢。

0 个答案:

没有答案