Image.FromStream() method returns Invalid Argument exception

Image.FromStream() expects a stream that contains ONLY one image!

It resets the stream.Position to 0. I’ve you have a stream that contains multiple images or other stuff, you have to read your image data into a byte array and to initialize a MemoryStream with that:

Image.FromStream(new MemoryStream(myImageByteArray));

The MemoryStream has to remain open as long as the image is in use.

I’ve learned that the hard way, too.

Leave a Comment