c# convert image formats to jpg

前端 未结 5 1561
予麋鹿
予麋鹿 2020-12-28 15:42

I need to get a picture from the user, with different format extensions, and I want to always save it as \"jpg\", for easy handling. is there a good way do that in c# withou

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-28 16:13

    I use this simple extension to convert a stream, all it does is convert it though and does nothing for quality.

    public static Stream ConvertImage(this Stream originalStream, ImageFormat format)
    {
                    var image = Image.FromStream(originalStream);
    
                    var stream = new MemoryStream();
                    image.Save(stream, format);
                    stream.Position = 0;
                    return stream;
    }
    

    usage:

    var outputStream = gifStream.ConvertImage(ImageFormat.Png);
    

提交回复
热议问题