I've got a bunch of images stored on disk, with the mimetype of the image stored in a database. If I want to save the image to disk I can use Image.Save(string)
(or the Async version) without needing to know the MimeType of the image.
However, if I want to save to a stream (for example, Response.Body
) then I have to use Image.Save(Stream, IImageEncoder)
.
How do I get the IImageEncoder
I need to save to the stream (without just declaring that "All my images ar png/jpeg/bmp" and using e.g. JpegEncoder
)?
ImageSharp can already tell you the mimetype of the input image. With your code if the mimetype doesn't match the input stream then the decode will fail.
What we are missing however in the current API v1.0.1 is the ability to save asynchronously while passing the format. We need to add that.