c# bitmap压缩

 1  public static ImageCodecInfo GetEncoderInfo(String mimeType)
 2 
 3         {
 4             int j;
 5             ImageCodecInfo[] encoders;
 6             encoders = ImageCodecInfo.GetImageEncoders();
 7             for (j = 0; j < encoders.Length; ++j)
 8             {
 9                 if (encoders[j].MimeType == mimeType)
10                     return encoders[j];
11             }
12             return null;
13         }
14         public static void savePath(Bitmap bmp, string str)//保存路径
15         {
16             ImageCodecInfo myImageCodecInfo;
17             System.Drawing.Imaging.Encoder myEncoder;
18             EncoderParameter myEncoderParameter;
19             EncoderParameters myEncoderParameters;
20 
21             myImageCodecInfo = GetEncoderInfo("image/jpeg");
22             myEncoder = System.Drawing.Imaging.Encoder.Quality;
23             myEncoderParameters = new EncoderParameters(1);
24             myEncoderParameter = new EncoderParameter(myEncoder, 80L);
25             myEncoderParameters.Param[0] = myEncoderParameter;
26             bmp.Save(str, myImageCodecInfo, myEncoderParameters); 
27         }

只需要传入Bitmap和路径,别的不需要修改.80L代表保存质量,还可以设置50L,25L,质量更差。

c# bitmap压缩

上一篇:c# Custom numeric format strings


下一篇:Winform中设置ZedGraph鼠标悬浮显示线上的点的坐标并自定义显示的内容