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];
MemoryStream imageStream1 = new MemoryStream(generatedImage);
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?
source
share