Alex Rivera | Logout

Get ImageFormat from System.Drawing.Image.RawFormat

Asked 2010-11-26T15:50:16.563
14

This code fails when trying to call Image.Save(MemoryStream, ImageFormat).

I get the exception:

a Value cannot be null.Parameter name: encoder"

ImageFormat format = generatedImage.RawFormat as ImageFormat;
image.ImageData = generatedImage.Save(format);

It works if I pass in an ImageFormat object directly e.g. ImageFormat.Jpeg.

What is the best way of converting the rawformat to ImageFormat (ideally without a switch statement or lots of if statements)

Thanks Ben

Edit
Report

1 Answer

8

are you looking for this?


System.Drawing.Imaging.ImageFormat fmt = new System.Drawing.Imaging.ImageFormat(generatedImage.RawFormat.Guid);
answered 2012-11-11T23:30:25.400

Your Answer