ImageCodecInfo jpgEncoder = imageHelper.GetEncoder(ImageFormat.Jpeg);
// define a target quality/fiedlity
System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality;
EncoderParameters myEncoderParameters = new EncoderParameters(1);
EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 80L);
myEncoderParameters.Param[0] = myEncoderParameter;
var ms = new MemoryStream(imgData); // imgData would come from db in this example
System.Drawing.Image image = System.Drawing.Image.FromStream(ms);
image.Save(filePath1, jpgEncoder, myEncoderParameters);
public ImageCodecInfo GetEncoder(ImageFormat format)
{
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();
foreach (ImageCodecInfo codec in codecs)
{
if (codec.FormatID == format.Guid)
{
return codec;
}
}
return null;
}