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);
The problem is that the resultant images are clearly aliased and changes to the InterpolationMode and SmoothingMode properties seem to make no difference.
Any pointers?
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));
As far as anti-aliasing goes, the most important parameter is graph.InterpolationMode
.
Thanks.
Try graphics.DrawImage(bmp, 0, 0, width, height); Also check this MSDN Article on interpolation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With