C# 实现图片压缩
程序员文章站
2022-06-04 08:45:54
代码: 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; }
代码:
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();
上一篇: ip route show命令
下一篇: oracle笔记触发器