Compare Arrays

  • Thread starter Thread starter Turbot
  • Start date Start date
T

Turbot

Hello,

Anyone know how to compare two byte arrays without going through each
item in the array. I actually want to compare two bitmap objects to see
if they both contain the same picture bit have been unable to do this.
I figured if I converted them to byte arrays there would be a simple
way of comparing them but I have had no luck.

Thanks in advance.

IAN
 
Hello,

Anyone know how to compare two byte arrays without going through each
item in the array. I actually want to compare two bitmap objects to see
if they both contain the same picture bit have been unable to do this.
I figured if I converted them to byte arrays there would be a simple
way of comparing them but I have had no luck.


For your image objects, can you just do:

If ImageA is ImageB then
Msgbox("Image Objects Identical")
End If

Maybe the IS clause may work for your byte arrays too?
 
For your image objects, can you just do:

If ImageA is ImageB then
Msgbox("Image Objects Identical")
End If

Maybe the IS clause may work for your byte arrays too?


Oops - please disregard. The IS operator only does Reference comparison -
not value comparison.
 
Lucas,

Sorry I break in an answer of you today again, however when I don't I think
it is not right as well.

Is compares if the addres of an object is the same as another object (and
than is the content as well the same).

Try this by instance
\\\
Public Class main
Public Shared Sub main()
Dim a As Image = Image.FromFile("c:\my.jpg")
Dim b As Image = a
Dim c As Image = Image.FromFile("c:\my.jpg")
If a Is b Then MessageBox.Show("we are equal")
If Not c Is a Then MessageBox.Show("We are not equal while we are")
End Sub
End Class
///

Sorry I felt I had to show you this,

Cor
 
Turbot,

What is wrong with looping through an array, how do you do that it is done
when there is a method, I think that it will be in a lot of cases even
faster.

See this all written in this message not tested and watch typos
\\\\
dim ImageIsUnequal as boolean
if arbyteA.length <> arbyteB.length then
ImageIsUnequal = true
Else
for i as integer = 0 to arrbyte.length -1
if arAbyte(i) <> arBbyte(i) then
ImageIsUnequal = true
exit for
Next
end if
///

I don't think that can much faster mostly it will be in the first comparing
already an unequal and when not than probably in the beginning of the for
loop.

I hope this helps?

Cor
 
Lucas,

My message was already gone when I saw your own correction.

So ignore my message.

:-)

Cor
 
confusing typo
What is wrong with looping through an array, how do you do that it is done
What is wrong with looping through an array, how do you think that it is
done
 
Hi,

Thanks for that. My main concern with comparing each byte in the array
was time but you are quite correct, most of the time, the length of the
byte array will be different so checking that first should give me a
negative result.
 
Back
Top