c#缩小图片后不清晰,要怎么缩小才能跟原来一样清晰。我用:System.Drawing.Bitmap缩小的。

发布网友 发布时间:2022-04-27 01:08

我来回答

3个回答

热心网友 时间:2023-11-15 06:57

正好之前有写过这个,不过是用的.net自带的api写的,如果想要弄的很好的话非常难,有兴趣可以看一下插值法,有若干种办法不一一列举。
/// <summary>
/// 获取缩小后的图片
/// </summary>
/// <param name="bm">要缩小的图片</param>
/// <param name="times">要缩小的倍数</param>
/// <returns></returns>
private Bitmap GetSmall(Bitmap bm, double times)
{
int nowWidth = (int)(bm.Width / times);
int nowHeight = (int)(bm.Height / times);
Bitmap newbm = new Bitmap(nowWidth, nowHeight);//新建一个放大后大小的图片

if (times >= 1 && times <= 1.1)
{
newbm = bm;
}
else
{
Graphics g = Graphics.FromImage(newbm);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.SmoothingMode = SmoothingMode.HighQuality;
g.CompositingQuality = CompositingQuality.HighQuality;
g.DrawImage(bm, new Rectangle(0, 0, nowWidth, nowHeight), new Rectangle(0, 0, bm.Width, bm.Height), GraphicsUnit.Pixel);
g.Dispose();
}
return newbm;
}

热心网友 时间:2023-11-15 06:58

我觉得你的问题是改变了图片的比例,造成图片失真,我建议你采用等比缩放的方法来缩小比例,而不是简单的在长和宽上各减去100。
可以参考如下方法
public static void GetThumbSize(ref int width,ref int height, int limitWidth,int limitHeight)
{
int scaling = width / height;
if (width > limitWidth)
{
width = limitWidth;
height = width / scaling;
}
if (height > limitHeight)
{
height = limitHeight;
width = height * scaling;
}
}
获得合适的长宽后在做你想要的操作

热心网友 时间:2023-11-15 06:58

插值法计算

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com