none
How can I compare two bitmaps (looking for dupes)? RRS feed

  • Question

  • I need to replace the image in one Picture Box with another. That means I must Dispose of the target before replacing it. Sometimes, that box contains a "default" ("No") image if blank. Unfortunately, if the program tries to replace the default/"No" with the same default/"No" image, disposing of the target disposes of the source!

    How can I compare the source & target image to see if they are the same image? I can't find a method that gives me the filename of the image in a PicBox, so I can't identify the image by name.

    I tried using the ".Tag" property to tag the source, but it only tags the PicBox itself, not its contents. So when I try reading the tag of the copy, the value is "Nothing".

    ' Defined an array of images for each icon called "thumbnails" earlier in the program.
    Try
    If thumbnails(intItem1).Image.Tag <> picBlank.Image.Tag Then ' This does not work, and trying to compare .image alone is invalid.
        thumbnails(intItem1).Image.Dispose()       ' Must dispose before we can modify.
       End If
    Catch
       ' Empty slots don't need to be disposed of. Ignore.
    End Try
    [...] thumbnails(intItem1).Image = picBlank.Image ' (Results in "invalid parameter" error when the images are the same file.)

    How can I obtain some unique identifying information about the source & destination PicBox contents to see if they contain the same image?

    TIA


    Monday, July 15, 2019 2:38 PM

Answers

All replies

  • Maybe like this:

       If Not Object.ReferenceEqual( thumbnails(intItem1).Image, picBlank.Image) Then

    Monday, July 15, 2019 5:12 PM
  • Maybe like this:

       If Not Object.ReferenceEqual( thumbnails(intItem1).Image, picBlank.Image) Then


    Thanks for the reply.

    <strike>Unfortunately, that doesn't seem to work either.  No matter what two images I compare, the result is always True. :(</strike>

    Oops, I made a mistake (forgot to change the reference). It *does* work! Thanks!

    (BTW: It's ".ReferenceEquals" with an "s" on the end.)



    Monday, July 15, 2019 7:08 PM