Parameter is not valid when getting image from stream

Posted by duka1 on Stack Overflow See other posts from Stack Overflow or by duka1
Published on 2010-06-14T10:46:25Z Indexed on 2010/06/14 10:52 UTC
Read the original article Hit count: 175

Filed under:

Hi guys,

I have this code:

              MemoryStream ms = new MemoryStream(newbytes, 0,
            newbytes.Length);
              ms.Position = 0;      
        ms.Write(newbytes, 0, newbytes.Length);
              Image img = Image.FromStream(ms);
            img.Save(@"C:\Users\gsira\Pictures\Blue hills5.jpg");

I get this error at the Image.FromStream(ms) call:

System.ArgumentException: Parameter is not valid. at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateIma

How can I resolve this? A couple of links which solve this problem (one on an MSDN thread) are broken so I am lost.

© Stack Overflow or respective owner

Related posts about c#