I am attempting to improve the performance of image resizing in C#. This StackOverflow answer provided some excellent pointers for improving performance.
I found these tips make a difference:
- Set pixel format to
PixelFormat.Format32bppPArgb
when creating a Bitmap. - Set
Graphics.CompositingMode
toCompositingMode.SourceCopy
. - Set
Graphics.InterpolationMode
toInterpolationMode.NearestNeighbor
.
However, the last piece of advice reduces the quality when resizing. This is particularly bad when creating thumbnails.
So how do the different interpolation modes compare against each other in performance?
(lower is better)
But how do they compare in image quality? I have scaled an image to 10% of it’s original size using each technique (slowest first).
Low
Bilinear
Bicubic
HighQualityBilinear
HighQualityBicubic
High
NearestNeighbor
Conclusion
It seems to me that the sweet spot is anything starting with ‘High’. These seem to have a good enough quality, and an acceptable performance. The NearestNeighbor
is really ugly, but if you want pure performance, or you’re not making a big difference to the scale, you might get away with it.