0

我正在尝试检查我的 panel0.background 图像是否与资源中的图像相同,然后将一些字符串添加到 arraylist。

这似乎不起作用:

If (Panel0.BackgroundImage Is My.Resources.Dinoback) Or (Panel0.BackgroundImage Is My.Resources.Dinoback2) Then
        Form1.jenisbuddyarr.Add("dino")
    ElseIf (Panel0.BackgroundImage Is My.Resources.Rabbitback) Or (Panel0.BackgroundImage Is My.Resources.Rabbitback2) Then
        Form1.jenisbuddyarr.Add("rabbit")
    ElseIf (Panel0.BackgroundImage Is My.Resources.Squirrelback) Or (Panel0.BackgroundImage Is My.Resources.Squirrelback2) Then
        Form1.jenisbuddyarr.Add("squirrel")
    End If
4

1 回答 1

0

问题是您当前的代码将检查它们是否来自同一个对象(事实并非如此)。检查此线程:在视觉上比较两个图像

Public Function AreSameImage(ByVal I1 As Image, ByVal I2 As Image) As Boolean
    Dim MS1 As New MemoryStream
    Dim MS2 As New MemoryStream
    I1.Save(MS1, ImageFormat.Bmp)
    I2.Save(MS2, ImageFormat.Bmp)
    For I As Integer = 0 To CInt(MS1.Length) - 1
      If MS1.ReadByte() <> MS2.ReadByte Then Return False
    Next
    Return True
End Function

If (AreSameImage(Panel0.BackgroundImage, My.Resources.Dinoback)) '...
于 2013-06-09T09:27:58.427 回答