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

<<  May 2018  >>
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

View posts in large calendar

RecentComments

TextBox