资 源 简 介
C#在转换图像格式时设置JPEG压缩级别,运行程序在窗口上单击按钮后,会生成多个版本不同压缩级别的图片,图片大小字节都不一样,如下代码是实现本功能的核心代码:
Bitmap MyBitmap = new Bitmap(@"J001.jpg");
ImageCodecInfo MyDecoder = null;
ImageCodecInfo[] MyDecoders = ImageCodecInfo.GetImageDecoders();
foreach (ImageCodecInfo MyFormat in MyDecoders)
{
if (MyFormat.FormatID == ImageFormat.Jpeg.Guid)
{
MyDecoder = MyFormat;
}
}
System.Drawing.Imaging.Encoder MyEncoder =
System.Drawing.Imaging.Encoder.Quality;
EncoderParameters MyEncoderParameters = new EncoderParameters(1);
//以50中级压缩图像
EncoderParameter MyEncoderParameter = new EncoderParameter(MyEncoder, 50L);
MyEncoderParameters.Param[0] = MyEncoderParameter;
MyBitmap.Save("J50L.jpg", MyDecoder, MyEncoderParameters);
//以100高级压缩图像
MyEncoderParameter = new EncoderParameter(MyEncoder, 100L);
MyEncoderParameters.Param[0] = MyEncoderParameter;
MyBitmap.Save("J99L.jpg", MyDecoder, MyEncoderParameters);
//以0低级压缩图像
MyEncoderParameter = new Enc