1

I need to convert byte array into Image type. My byte array contains raw image and the image is valid. I have tried all solution from net but still getting the error:

Parameter is not valid.

Following is my code:

byte[] arr = File.ReadAllBytes(@"C:\Users\aa\Desktop\Image.raw");
MemoryStream ms = new MemoryStream(arr,0,arr.Length);        
ms.Seek(0, SeekOrigin.Begin);
Image img = Image.FromStream(ms);
ms.Dispose();                                                                        

I have also tried with:

using(MemoryStream ms = new MemoryStream(arr,0,arr.Length))
{
     //my code 
}
rhughes
  • 9,257
  • 11
  • 59
  • 87
  • 2
    I'm not sure GDI+ knows how to read RAW image files. You might need a separate library: http://stackoverflow.com/questions/227604/reading-raw-image-files-as-gdi-bitmaps – acfrancis Jun 20 '14 at 11:52
  • How big is the image? – Bas Jun 20 '14 at 11:52

1 Answers1

2

The documentation for Image.FromStream is missing the relevant part that does exist in the Image.FromFile documentation:

Managed GDI+ has built-in encoders and decoders that support the following file types:

  • BMP
  • GIF
  • JPEG
  • PNG
  • TIFF

Your file isn't in one of those types, so you'll need to figure out some way to convert the file to an accepted type first. Depending on your needs, it might be acceptable to use a tool like ImageMagick's convert utility to perform this conversion automatically, and read in the result of that conversion.

Community
  • 1
  • 1