代碼: private static ImageCodecInfo GetImageCodecInfo(ImageFormat imageFormat) { ImageCodecInfo[] imageCodecInfoArr = ImageCodecInfo.GetImageDecoders(); ...
代碼:
private static ImageCodecInfo GetImageCodecInfo(ImageFormat imageFormat) { ImageCodecInfo[] imageCodecInfoArr = ImageCodecInfo.GetImageDecoders(); foreach (ImageCodecInfo imageCodecInfo in imageCodecInfoArr) { if (imageCodecInfo.FormatID == imageFormat.Guid) { return imageCodecInfo; } } return null; }View Code
代碼:
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();View Code