public static ImageCodecInfo GetEncoder(ImageFormat format)
{
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();
foreach (ImageCodecInfo codec in codecs)
{
if (codec.FormatID == format.Guid)
return codec;
}
return null;
}
Bitmap im = 这里是原图片
//转成jpg
var eps = new EncoderParameters();
var ep = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 85L);
eps.Param[] = ep;
var jpsEncodeer = GetEncoder(ImageFormat.Jpeg);
//保存图片
imgurl = @"/Content/Upload/" + guid + extension;
im.Save(path + imgurl,jpsEncodeer,eps);
//释放资源
im.Dispose();
ep.Dispose();
eps.Dispose();
05-11 19:19