C# 实现图片压缩

2021-07-15 00:15

阅读:610

标签:span   压缩   com   util   bmp   pdo   click   cin   isp   

代码:

技术分享图片技术分享图片
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

 

C# 实现图片压缩

标签:span   压缩   com   util   bmp   pdo   click   cin   isp   

原文地址:https://www.cnblogs.com/s0611163/p/9529497.html


评论


亲,登录后才可以留言!