求一个图片压缩率高一点的方法

hercules135 hercules135 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

public static void thumb(string rSrcImgPath, string rDstImgPath, int width, string lv = "h", int height = 0)
{
//利用Image对象装载源图像
System.Drawing.Image image = System.Drawing.Image.FromFile(rSrcImgPath);

//创建一个System.Drawing.Bitmap对象,并设置你希望的缩略图的宽度和高度。
int thumbWidth, thumbHeight;
double srcWidth = image.Width;
double srcHeight = image.Height;
if (height == 0)//如果高度height为0,则原比例缩放
{
thumbWidth = width;
double d = srcHeight / srcWidth;
thumbHeight = Convert.ToInt32( d * width );
}
else//否则按要求宽高生成
{
thumbWidth = width;
thumbHeight = height;
}
Bitmap bmp = new Bitmap(thumbWidth, thumbHeight);

//从Bitmap创建一个System.Drawing.Graphics对象,用来绘制高质量的缩小图。
System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(bmp);

if (lv=="h")
{
//设置 System.Drawing.Graphics对象的SmoothingMode属性为HighQuality
gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//下面这个也设成高质量
gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
//下面这个设成High
gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
}
else if (lv=="m")
{
gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;

gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.Default;

gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Default;

}
else if (lv=="l")
{
gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;

gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;

gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Low;
}



//把原始图像绘制成上面所设置宽高的缩小图
System.Drawing.Rectangle rectDestination = new System.Drawing.Rectangle(0, 0, thumbWidth, thumbHeight);
gr.DrawImage(image, rectDestination, 0, 0,Convert.ToInt32( srcWidth),Convert.ToInt32( srcHeight), GraphicsUnit.Pixel);

//保存图像,大功告成!
bmp.Save(rDstImgPath);

//最后别忘了释放资源
bmp.Dispose();
image.Dispose();
}


现在用的这个图片压缩方法,感觉质量太高...也就是体积太大,请问有没有压缩的更狠一点的方法,新人求推荐啊
...全文
评论 6
收藏 已收藏
分享
返回顶部
hercules135
C# 111,128 成员 642,536 内容