Comparing Two Image Problems

I want to compare two bytes by bytes. Both are 8-bit BMP images and are exactly 40,000 bytes in size. The first image is generated in memory as an array of bytes, the second is read from the file into the image object.

I use instances MemoryStreamto compare:

    byte[] generatedImage = new byte[40000];
    // some unrelated logic of image generation ...
    MemoryStream imageStream1 = new MemoryStream(generatedImage);

    // loaded image, 200x200 bmp - 40000 bytes
    MemoryStream imageStream2 = new MemoryStream();
    Image loadedImage = Image.FromFile("image.bmp");
    loadedImage.Save(imageStream2, ImageFormat.Bmp);

The problem is that the memory stream of the downloaded image imageStream2contains more than 40,000 bytes, as I understand it, it contains some information about the BMP itself. Thus, the second stream is created with Lengthequal 41078 and Positionequal to 1278. I would understand if it was Positionequal to 1078, but this is not so, and less than 40,000 bytes are left from the position.

In my algorithm, I need to compare images as quickly as possible, so I abandoned the idea of ​​creating raster images and comparing using the method GetPixel. I use the method MemoryStream.ReadBytefor comparison.

How can I get the “real” BMP bytes from the second Stream? Is there any way in this case to compare images from byte to byte?

+3
source share
4 answers

http://en.wikipedia.org/wiki/BMP_file_format#Bitmap_file_header

Read 4 bytes with an offset of 10 to get the pixel data offset. Read 4 bytes at offset 2 to get the size of the whole thing, including the header. Subtract the first of the last to get the pixel data size.

+2
source

# . ( - GetPixel) , 25 :

http://danbystrom.se/2008/12/14/improving-performance/

, , , , . .

, . 32bpp. 24bpp- ( .), "" , 32bpp. "" , , .

+3

All Articles