无缘无故地获取OperationShouldNotOverflow

时间:2016-08-18 19:07:21

标签: vb.net image exception bitmap

我正在创建一个功能来检测两个图像之间的移动,并且我没有明显的理由得到OperationShouldNotOverflow,有人可以帮助我吗?

我的所有变量都被初始化了一个I verifie mi bitmaps在调用函数之前并不是什么

Function isDiff(ByVal bmp As Bitmap, ByVal bmpn As Bitmap, ByVal thr As Integer) As Boolean

    Try
        Dim w As Integer = bmp.Width
        Dim h As Integer = bmp.Height

        p1 = bmp.GetPixel(w / 4, h / 4).R + bmp.GetPixel(w / 4, h / 4).G + bmp.GetPixel(w / 4, h / 4).B
        p2 = bmp.GetPixel(w / 2, h / 4).R + bmp.GetPixel(w / 2, h / 4).G + bmp.GetPixel(w / 2, h / 4).B
        p3 = bmp.GetPixel(w * 0.75, h / 4).R + bmp.GetPixel(w * 0.75, h / 4).G + bmp.GetPixel(w * 0.75, h / 4).B
        p4 = bmp.GetPixel(w / 4, h / 4).R + bmp.GetPixel(w / 4, h / 4).G + bmp.GetPixel(w / 4, h / 4).B
        p5 = bmp.GetPixel(w / 2, h / 4).R + bmp.GetPixel(w / 2, h / 4).G + bmp.GetPixel(w / 2, h / 4).B
        p6 = bmp.GetPixel(w * 0.75, h / 4).R + bmp.GetPixel(w * 0.75, h / 4).G + bmp.GetPixel(w * 0.75, h / 4).B
        p7 = bmp.GetPixel(w / 4, h / 4).R + bmp.GetPixel(w / 4, h / 4).G + bmp.GetPixel(w / 4, h / 4).B
        p8 = bmp.GetPixel(w / 4, h / 4).R + bmp.GetPixel(w / 4, h / 4).G + bmp.GetPixel(w / 4, h / 4).B
        p9 = bmp.GetPixel(w / 4, h / 4).R + bmp.GetPixel(w / 4, h / 4).G + bmp.GetPixel(w / 4, h / 4).B

        pp1 = bmpn.GetPixel(w / 4, h / 4).R + bmpn.GetPixel(w / 4, h / 4).G + bmpn.GetPixel(w / 4, h / 4).B
        pp2 = bmpn.GetPixel(w / 2, h / 4).R + bmpn.GetPixel(w / 2, h / 4).G + bmpn.GetPixel(w / 2, h / 4).B
        pp3 = bmpn.GetPixel(w * 0.75, h / 4).R + bmpn.GetPixel(w * 0.75, h / 4).G + bmpn.GetPixel(w * 0.75, h / 4).B
        pp4 = bmpn.GetPixel(w / 4, h / 4).R + bmpn.GetPixel(w / 4, h / 4).G + bmpn.GetPixel(w / 4, h / 4).B
        pp5 = bmpn.GetPixel(w / 2, h / 4).R + bmpn.GetPixel(w / 2, h / 4).G + bmpn.GetPixel(w / 2, h / 4).B
        pp6 = bmpn.GetPixel(w * 0.75, h / 4).R + bmpn.GetPixel(w * 0.75, h / 4).G + bmpn.GetPixel(w * 0.75, h / 4).B
        pp7 = bmpn.GetPixel(w / 4, h / 4).R + bmpn.GetPixel(w / 4, h / 4).G + bmpn.GetPixel(w / 4, h / 4).B
        pp8 = bmpn.GetPixel(w / 4, h / 4).R + bmpn.GetPixel(w / 4, h / 4).G + bmpn.GetPixel(w / 4, h / 4).B
        pp9 = bmpn.GetPixel(w / 4, h / 4).R + bmpn.GetPixel(w / 4, h / 4).G + bmpn.GetPixel(w / 4, h / 4).B

        If p1 > pp1 + thr And p1 < pp1 - thr Then
            Return False
        End If

        If p2 > pp2 + thr And p2 < pp2 - thr Then
            Return False
        End If

        If p3 > pp3 + thr And p3 < pp3 - thr Then
            Return False
        End If

        If p4 > pp4 + thr And p4 < pp4 - thr Then
            Return False
        End If

        If p5 > pp5 + thr And p5 < pp5 - thr Then
            Return False
        End If

        If p6 > pp6 + thr And p6 < pp6 - thr Then
            Return False
        End If

        If p7 > pp7 + thr And p7 < pp7 - thr Then
            Return False
        End If

        If p8 > pp8 + thr And p8 < pp8 - thr Then
            Return False
        End If

        If p9 > pp9 + thr And p9 < pp9 - thr Then
            Return False
        End If

        Return True
    Catch ex As Exception
        MsgBox(ex.Message)
        Return True
    End Try

End Function

希望有人可以提供帮助:)

0 个答案:

没有答案