一、C# GDI+ Image对象保存图片质量
Image bmp = Bitmap.FromFile("3.png"); //默认保存质量 预估80% bmp.Save("default3.jpg", ImageFormat.Jpeg); //保存质量 ImageCodecInfo myImageCodecInfo = GetEncoderInfo("image/jpeg"); System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality; EncoderParameters myEncoderParameters = new EncoderParameters(1); //25L EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 25L); myEncoderParameters.Param[0] = myEncoderParameter; bmp.Save("default25.jpg", myImageCodecInfo, myEncoderParameters); //50L myEncoderParameter = new EncoderParameter(myEncoder, 50L); myEncoderParameters.Param[0] = myEncoderParameter; bmp.Save("default50.jpg", myImageCodecInfo, myEncoderParameters); //100L myEncoderParameter = new EncoderParameter(myEncoder, 100L); myEncoderParameters.Param[0] = myEncoderParameter; bmp.Save("default100.jpg", myImageCodecInfo, myEncoderParameters);
效果:
default.jpg +default25.jpg效果
二、Image.Save() 详细说明:
Image.Save方法共有五种重载 其中Save(String, ImageCodecInfo, EncoderParameters)和Save(Stream, ImageCodecInfo,EncoderParameters)这两种方法课以调节图像质量。 Save.(string ,ImageCodeInfo,EncoderParameters) 使用方法:参数:
filename 类型:System.String 字符串,包含要将此 Image 保存到的文件的名称。
encoder 类型:System.Drawing.Imaging.ImageCodecInfo 此 Image 的 ImageCodecInfo。
encoderParams 类型:System.Drawing.Imaging.EncoderParameters 用于该 Image 的 EncoderParameters。
获取编码器
ImageCodecInfo myImageCodecInfo; //获得JPEG格式的编码器 myImageCodecInfo = GetEncoderInfo("image/jpeg");
设置图像质量
System.Drawing.Imaging.Encoder myEncoder; EncoderParameter myEncoderParameter; EncoderParameters myEncoderParameters; // for the Quality parameter category. myEncoder = System.Drawing.Imaging.Encoder.Quality; // EncoderParameter object in the array. myEncoderParameters = new EncoderParameters(1); //设置质量 数字越大质量越好,但是到了一定程度质量就不会增加了,MSDN上没有给范围,只说是32为非负整数 myEncoderParameter = new EncoderParameter(myEncoder, 100L); myEncoderParameters.Param[0] = myEncoderParameter;
更多:
标签:C#,myEncoderParameter,myEncoder,保存,System,myEncoderParameters,EncoderParameters, From: https://www.cnblogs.com/tianma3798/p/17658797.html