我有一些C#代码调整了我认为非常典型的图像大小:
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属性的更改似乎没有区别.
有什么指针吗?
它变成了代码错误.它实际上是在Bitmap构造函数中没有插值的情况下调整图像大小,然后尝试将该版本平滑地调整到它已经存在的大小.这是修改后的代码:
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
.
谢谢.