【问题标题】:Compare Panel BackGround Image with Resource Image将面板背景图像与资源图像进行比较
【发布时间】:2013-06-09 08:53:03
【问题描述】:

我正在尝试检查我的 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

【问题讨论】:

  • 对,这行不通,因为每次在代码中使用 My.Resources.Foo 时,都会得到一个 new 图像对象。您需要在表单中添加 Image 类型的变量,并在表单构造函数中只分配一次。或者使用单独的变量跟踪面板中的内容。

标签: vb.net image panel


【解决方案1】:

问题是您当前的代码将检查它们是否来自同一个对象(事实并非如此)。检查此线程:Comparing two images visually

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)) '...

【讨论】:

    猜你喜欢
    • 2011-09-12
    • 2011-09-15
    • 2015-01-23
    • 1970-01-01
    • 1970-01-01
    • 2013-11-30
    • 1970-01-01
    • 1970-01-01
    • 2019-04-16
    相关资源
    最近更新 更多