Say no to crappy images in your Delphi programs. Finding the best resizing algorithm.

So, because I built a program that has to resize/scale images up and down, I built this tool to test 13 resizing algorithms for Delphi.

Tested algorithms

  • JanFX SmoothResize
  • JanFX Stretch
  • Transform (from Graphics32)
  • HB (Private)
  • madGraphics (from madShi)
  • VCL.ScaleImage (from Embarcadero)
  • VCL.Stretch (from Embarcadero)
  • SmoothResize (assembler)
  • Windows Thumbnail (Windows API)
  • Windows StretchBlt (Windows API)
  • FMX.CreateThumbnail (from Embarcadero)
  • Windows.WIC (Windows API)
  • Windows.GDI (Windows API)

Tests:

  • Resample up
  • Resample down

Two of the above tests include 3rd party algorithms.
If you don’t have access to their source code, you will have to switch off the {$3RDPARTY} switch.

Test program

You can find the source code, the precompiled EXE file and some test images (high res/low res) on GitHub.

Most algorithms you will find in my LightSaber library. The Graphics32 lib you can get from GitHub.


Experiments

Scale down

Here are the results for the scale down test. I split the result in two categories: smooth and sharp. It is difficult to say which category is better. It depends on your taste.

Sharp results:

The images are listed in this order: JanFX SmoothResize (1ms), Gr32 3 (33ms), madGraphics (1ms), VCL.Stretch (1ms), SmoothResize ASM (1ms), FMX.CreateThumbnail (1120ms).

Note: the difference between the images is very obvious when you click into the program to quickly switch between the images/algorithms.

Smooth results:

In this experiment we decrease the size of the input JPG image from 5300 pixels wide to only 200. There is no clear winner here. Most algorithms produce almost the same output. The algorithms are in this order:

JanFX Stretch (120 to 491ms depending on the filter settings), VCL.ScaleImage (39ms), Windows.WIC (87ms), Windows.GDI (87ms), Windows.Thumbnail (3ms).

The last algorithm is the fastest of them all and also produces a slightly better image (less dark and fuzzy): Windows.StretchBlt (32ms).

Scale up

In this experiment we increase the size of the input image “Face 256.png” from 256 pixels to 1900. If in “scale down” experiment most algorithms performed almost identical, here things are much different. Some algorithms could be 10x faster than others, while still producing similar quality.

Here are their performance:

Too smooth
Windows.GDI (5ms)
Gr32 3 (84ms)
JanFX SmoothResize (10ms)
madGraphics (3ms)
SmoothResize ASM (5ms)

Good
FMX.CreateThumbnail (1198ms)
Windows.StretchBlt (3ms) [Best]
Windows.WIC (5ms) [Second runner]

Too blocky
VCL.Stretch (0ms) [Unusable]
VCL.ScaleImage (21ms)
JanFX Stretch-5 (10ms)

Conclusions
The winner is Windows.StretchBlt, which works best in both cases (resize up/down) and it is also the fastest.
In resize up, the Embarcadero algorithms came out the worst, but at least VCL.Stretch was the fastest (under 1ms).

Leave a Comment

Scroll to Top