代码:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
private static ImageCodecInfo GetImageCodecInfo(ImageFormat imageFormat) { ImageCodecInfo[] imageCodecInfoArr = ImageCodecInfo.GetImageDecoders(); foreach (ImageCodecInfo imageCodecInfo in imageCodecInfoArr) { if (imageCodecInfo.FormatID == imageFormat.Guid) { return imageCodecInfo; } } return null; }
代码:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
MemoryStream ms = HttpUtil.HttpDownloadFile(url); Bitmap bmp = new Bitmap(ms); EncoderParameters encoderParameters = new EncoderParameters(1); EncoderParameter encoderParameter = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 75L); encoderParameters.Param[0] = encoderParameter; MemoryStream msCompress = new MemoryStream(); bmp.Save(msCompress, GetImageCodecInfo(ImageFormat.Jpeg), encoderParameters); Bitmap bmpCompress = new Bitmap(msCompress); bmpCompress.Save(path); bmp.Save(path2); msCompress.Close(); ms.Close();