在 .Net 中使用抗锯齿调整图像大小 [英] Image resizing in .Net with Antialiasing

查看:32
本文介绍了在 .Net 中使用抗锯齿调整图像大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些调整图像大小的 C# 代码,我认为这些代码非常典型:

I've got some C# code that resizes images that I think is pretty typical:

Bitmap bmp = new Bitmap(image, new Size(width, height));
Graphics graphics = Graphics.FromImage(bmp);
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.DrawImage(bmp, width, height);

问题是生成的图像明显有锯齿,对 InterpolationMode 和 SmoothingMode 属性的更改似乎没有任何区别.

The problem is that the resultant images are clearly aliased and changes to the InterpolationMode and SmoothingMode properties seem to make no difference.

有什么指点吗?

推荐答案

原来代码错了.它实际上是在 Bitmap 构造函数中没有插值的情况下调整图像的大小,然后尝试将该版本的大小平滑地调整到它已经达到的大小.修改后的代码如下:

It turns the code was just wrong. It was actually resizing the image without interpolation in the Bitmap constructor, and then attempting to smoothly resize that version to the size it was already at. Here is the amended code:

Bitmap bmp = new Bitmap(width, height);
Graphics graph = Graphics.FromImage(bmp);
graph.InterpolationMode = InterpolationMode.High;
graph.CompositingQuality = CompositingQuality.HighQuality;
graph.SmoothingMode = SmoothingMode.AntiAlias;
graph.DrawImage(image, new Rectangle(0, 0, width, height));

就抗锯齿而言,最重要的参数是graph.InterpolationMode.

As far as anti-aliasing goes, the most important parameter is graph.InterpolationMode.

谢谢.

这篇关于在 .Net 中使用抗锯齿调整图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆