I'm trying to use a MemoryStream to turn an image into a byte array, however, the image looks different when I recover it.
I made a simple Form app to show the issue. I'm using the google chrome Icon for this example:
var process = Process.GetProcessById(3876); // found pid manually
var image = Icon.ExtractAssociatedIcon(process.MainModule.FileName).ToBitmap();
pictureBox1.Image = image;
byte[] imageBytes;
using (var ms = new MemoryStream())
{
image.Save(ms, ImageFormat.Bmp);
imageBytes = ms.ToArray();
}
using (var ms = new MemoryStream(imageBytes))
{
pictureBox2.Image = (Bitmap) Image.FromStream(ms);
}
Result:
Any idea what I'm missing here?
Update I was able to get the proper bytes using the following code:
var converter = new ImageConverter();
var imageBytes = (byte[]) converter.ConvertTo(image, typeof(byte[]));
Would still like to know whats up with the Memory stream though..
