I am currently working on a project which modify some images and save it again. However, I have noticed that sometimes the resulted image is drastically different than the original one in terms of file size in bytes. Even if the modifications were very small such as changing colour on a single pixel. So I decided to do this experiment where I load an image and save it again immediately to new file without any changes (using C# Bitmap class). I was expecting to get the same size in both files but unfortunately the actual sizes were not identical. Here is my code:
String originalImagePath = "image.png";
String savedImagePath = "image2.png";
Bitmap image = new Bitmap(originalImagePath);
image.Save(savedImagePath);
Assert.AreEqual(new FileInfo(originalImagePath).Length, new FileInfo(savedImagePath).Length);
Assert.AreEqual failed.
Expected:<218144>.Actual:<344264>.
Should both files have the same sizes? If no, then what I am missing here?
And how can I generate identical file?
Here is the image that I am using:
PNG Image