Code
1 Jpg保存图片确认质量#region Jpg保存图片确认质量
2 /**//**/
3 /**//// <summary>
4 /// 保存JPG时用
5 /// </summary>
6 /// <param name="mimeType"></param>
7 /// <returns>得到指定mimeType的ImageCodecInfo</returns>
8 private static ImageCodecInfo GetCodecInfo(string mimeType)
9 {
10 ImageCodecInfo[] CodecInfo = ImageCodecInfo.GetImageEncoders();
11 foreach (ImageCodecInfo ici in CodecInfo)
12 {
13 if (ici.MimeType == mimeType) return ici;
14 }
15 return null;
16 }
17
18
19 /**//**/
20 /**//// <summary>
21 /// 保存为JPEG格式,支持压缩质量选项
22 /// </summary>
23 /// <param name="bmp"></param>
24 /// <param name="FileName"></param>
25 /// <param name="Qty">1~100</param>
26 /// <returns></returns>
27 public void SaveAsJPEG(Image bmp, string FileName, int Qty)
28 {
29 try
30 {
31 EncoderParameter p;
32 EncoderParameters ps;
33
34 ps = new EncoderParameters(1);
35
36 p = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, Qty);
37 ps.Param[0] = p;
38
39 bmp.Save(FileName, GetCodecInfo("image/jpeg"), ps);
40
41
42 }
43 catch
44 {
45
46 }
47
48 }
1 Jpg保存图片确认质量#region Jpg保存图片确认质量
2 /**//**/
3 /**//// <summary>
4 /// 保存JPG时用
5 /// </summary>
6 /// <param name="mimeType"></param>
7 /// <returns>得到指定mimeType的ImageCodecInfo</returns>
8 private static ImageCodecInfo GetCodecInfo(string mimeType)
9 {
10 ImageCodecInfo[] CodecInfo = ImageCodecInfo.GetImageEncoders();
11 foreach (ImageCodecInfo ici in CodecInfo)
12 {
13 if (ici.MimeType == mimeType) return ici;
14 }
15 return null;
16 }
17
18
19 /**//**/
20 /**//// <summary>
21 /// 保存为JPEG格式,支持压缩质量选项
22 /// </summary>
23 /// <param name="bmp"></param>
24 /// <param name="FileName"></param>
25 /// <param name="Qty">1~100</param>
26 /// <returns></returns>
27 public void SaveAsJPEG(Image bmp, string FileName, int Qty)
28 {
29 try
30 {
31 EncoderParameter p;
32 EncoderParameters ps;
33
34 ps = new EncoderParameters(1);
35
36 p = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, Qty);
37 ps.Param[0] = p;
38
39 bmp.Save(FileName, GetCodecInfo("image/jpeg"), ps);
40
41
42 }
43 catch
44 {
45
46 }
47
48 }