Equals Method Fails for Identical Bitmaps?

F

Fir5tSight

Hi All,

I have two identical PDF files, say file1 and file2. I used an API
package to extract the bitmap in each PDF file, say bitmap1 (in file1)
and bitmap2 (in file2). Since the bitmaps are same in both files, I
expect bitmap1.Equals (bitmap2) to return true. However, it's false.

FYI:

1) I've copied file1 to file2, therefore, the bitmap images in both
files are exactly the same;
2) The API gets the correct bitmap image in either file because I'm
able to save either to a ".tif" file, and am also able to display it in
a PictureBox control.

Could anyone tell me why?

Thanks!

-Emily
 
J

Jon Skeet [C# MVP]

Fir5tSight said:
I have two identical PDF files, say file1 and file2. I used an API
package to extract the bitmap in each PDF file, say bitmap1 (in file1)
and bitmap2 (in file2). Since the bitmaps are same in both files, I
expect bitmap1.Equals (bitmap2) to return true. However, it's false.

FYI:

1) I've copied file1 to file2, therefore, the bitmap images in both
files are exactly the same;
2) The API gets the correct bitmap image in either file because I'm
able to save either to a ".tif" file, and am also able to display it in
a PictureBox control.

Could anyone tell me why?

Yes - Bitmap and Image don't override Equals. In this case, I'm not
entirely surprised - there are plenty of candidates for having an
Equals override before we get down to images. The number of developers
whoe would use it is probably very small compared with, say, Array.
 
R

R. MacDonald

Hello, Emily,

As Jon says, Equals hasn't been overridden for this type. This means
that Equals will be True for two Image type variables only if they refer
to the same object. Equals between two distinct image objects will
return False even if those objects hold exactly the same data. (I guess
this is essentially the same thing as the "Is" operator in VB.)

You and I seem to be among that very small number of developers that Jon
refers to who would prefer that Image.Equals had been overridden to
provide value equality.

In my case, I loaded the images into a byte arrays to compare them.
Perhaps someone can provide suggestions for a better way to do this. (I
imagine that there is one, but didn't have time to seek it out.)

Cheers,
Randy
 
F

Fir5tSight

Hi Randy, Jon,

Many thanks for answering my question! I'll do what you suggest - To
load the images into two byte arrays and compare the arrays.

-Emily
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top