0

I'm trying to create an image from the memory stream in which the image is a 32bit depth JPG.

byte[] imgData = File.ReadAllBytes(@"C:\ABC\32bit.jpg");
using (var ms = new MemoryStream(imgData))
    {
        Image img = Image.FromStream(ms, false); // Exception line "Parameter is not valid"
    } 

Actually it works for many images which is either 24bit or even a 32bit PNG. It just not works for 32bit JPG image.

Have tried these below solutions,

1

 Image x = (Bitmap)((new ImageConverter()).ConvertFrom(imgData));

2

 System.Drawing.ImageConverter converter = new System.Drawing.ImageConverter();
 Image img = (Image)converter.ConvertFrom(imgData);

3

 ms.Seek(0, SeekOrigin.Begin);

4

Bitmap bitmap = (Bitmap)Image.FromStream(ms , true, false)

Any help on the possible error?

A Coder
  • 3,039
  • 7
  • 58
  • 129
  • Look at this: https://stackoverflow.com/questions/629955/parameter-not-valid-exception-loading-system-drawing-image – BWA Jan 19 '22 at 11:34
  • @BWA I think that's my 4th solution which i have tried. Didn't help – A Coder Jan 19 '22 at 11:39
  • You'll have to go shopping for a codec to handle this format, you won't get it from System.Drawing. WIC has better support, https://stackoverflow.com/questions/2284353/is-there-a-good-way-to-convert-between-bitmapsource-and-bitmap – Hans Passant Jan 19 '22 at 11:52

0 Answers0