I have two c# functions that convert byte[] to images and back. I thought that the two functions would be exactly reversible:
public static byte[] ImageToByte(System.Drawing.Image image, System.Drawing.Imaging.ImageFormat format)
{
using (MemoryStream ms = new MemoryStream())
{
// Convert Image to byte[]
image.Save(ms, format);
byte[] imageBytes = ms.ToArray();
return imageBytes;
}
}
public static Image ByteToImage(byte[] imageBytes)
{
using (MemoryStream ms = new MemoryStream())
{
ms.Write(imageBytes, 0, imageBytes.Length);
Image returnImage = Image.FromStream(ms);
return returnImage;
}
}
However, if i look at the original byte array and then converted/reconverted array they are different (different lengths). I am not clear why? I would like to be able to tell if the image has been modified in my app so need to be able to compare the image array before and after.
Thanks