Parameter is not valid error in MemoryStream

Encountered the following exception which was caused by converting a byte[] which originated from a BMP to an Image.

 

public static Image ToImage(this byte[] value)

        {

            Image returnImage;

            using (MemoryStream ms = new MemoryStream(value))

            {

                returnImage = Image.FromStream(ms);

            }

 

            return returnImage;

        }

 

System.ArgumentException was unhandled by user code

  HResult=-2147024809

  Message=Parameter is not valid.

  Source=System.Drawing

  StackTrace:

       at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)

       at System.Drawing.Image.FromStream(Stream stream)

 

I will try to solve this in the near future. It works though with all other image formats.

Add comment

biuquote
  • Comment
  • Preview
Loading

Sponsored by

Calendar

<<  November 2018  >>
MoTuWeThFrSaSu
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

View posts in large calendar

RecentComments

TextBox