[GH-ISSUE #387] [Feature Request] Add other image scaling algorithms like bilinear or bicubic #1688

Open
opened 2026-03-01 18:47:30 +03:00 by kerem · 1 comment
Owner

Originally created by @Naetmul on GitHub (Oct 15, 2018).
Original GitHub issue: https://github.com/NickeManarin/ScreenToGif/issues/387

Originally assigned to: @NickeManarin on GitHub.

Problem

The image resized to ~50% of the original size with ScreenToGif showed visibly lower quality than the image resized to ~50% of the original size with Photoshop. The former image had some visible artifacts (something like over-sharpening) due to the scaling.

This kind of problem will also apply when enlarging images.

Cause

System.Windows.Media, which is used in WPF, uses "linear" scaling as the default scaling algorithm as stated in the MS document.
There are also other algorithms in System.Windows.Media: NearestNeighbor (lower quality than linear) and Fant (higher quality than linear).
The problem is that all the supported scaling algorithms of System.Windows.Media, which are NearestNeighbor, Linear, Fant, do not give us good results.

This is discussed in a StackOverflow question and VirtualDub blog.
The followings are talking about the Fant algorithm, which is the highest quality algorithm among them:

In practice, it's a lot more blurry for downscaling than GDI's cubic downscaling, so the theory about averaging sounds about right.

It turns out that Fant's algorithm is... a box filter. More specifically, it is equivalent to linear interpolation for enlargement along an axis and a box filter for decimation.
... it showed more aliasing than a conventional triangle filter (precise bilinear in VirtualDub) or bicubic decimation filter -- not too surprising for a box filter.

It's also a somewhat awkward limitation since .NET has already had decent bilinear and bicubic decimation support available through System.Drawing (GDI+). Therefore, if you sometimes need to downscale images in your WPF based UI, you might consider prescaling them through GDI+ instead to get better quality.

Therefore, adding the Fant algorithm only seems easy (because we only need to change the option parameter), but it seems not so good.

Suggestion

Add other image scaling algorithms like "bilinear" or "bicubic" scaling algorithms.

Notes

They are already in GDI+ (System.Drawing), but they are not available in System.Windows.Media.

Some notes when using GDI+'s bicubic scaling: InterpolationMode HighQualityBicubic introducing artefacts on edge of resized images

Originally created by @Naetmul on GitHub (Oct 15, 2018). Original GitHub issue: https://github.com/NickeManarin/ScreenToGif/issues/387 Originally assigned to: @NickeManarin on GitHub. ### Problem The image resized to ~50% of the original size with ScreenToGif showed visibly lower quality than the image resized to ~50% of the original size with Photoshop. The former image had some visible artifacts (something like over-sharpening) due to the scaling. This kind of problem will also apply when enlarging images. ### Cause `System.Windows.Media`, which is used in WPF, uses "linear" scaling as the default scaling algorithm as stated in [the MS document](https://docs.microsoft.com/en-us/dotnet/api/system.windows.media.bitmapscalingmode). There are also other algorithms in `System.Windows.Media`: NearestNeighbor (lower quality than linear) and Fant (higher quality than linear). The problem is that all the supported scaling algorithms of `System.Windows.Media`, which are NearestNeighbor, Linear, Fant, do not give us good results. This is discussed in [a StackOverflow question](https://stackoverflow.com/questions/2018881/imageprocessing-in-wpf-fant-bitmapscalingmode) and [VirtualDub blog](http://www.virtualdub.org/blog/pivot/entry.php?id=300). The followings are talking about the Fant algorithm, which is the highest quality algorithm among them: > In practice, it's a lot more blurry for downscaling than GDI's cubic downscaling, so the theory about averaging sounds about right. > It turns out that Fant's algorithm is... a box filter. More specifically, it is equivalent to linear interpolation for enlargement along an axis and a box filter for decimation. > ... it showed more aliasing than a conventional triangle filter (precise bilinear in VirtualDub) or bicubic decimation filter -- not too surprising for a box filter. > It's also a somewhat awkward limitation since .NET has already had decent bilinear and bicubic decimation support available through System.Drawing (GDI+). Therefore, if you sometimes need to downscale images in your WPF based UI, you might consider prescaling them through GDI+ instead to get better quality. Therefore, adding the Fant algorithm only seems easy (because we only need to change the option parameter), but it seems not so good. ### Suggestion Add other image scaling algorithms like "bilinear" or "bicubic" scaling algorithms. ### Notes They are already in GDI+ ([`System.Drawing`](https://docs.microsoft.com/en-us/dotnet/api/system.drawing.drawing2d.interpolationmode)), but they are not available in `System.Windows.Media`. Some notes when using GDI+'s bicubic scaling: [InterpolationMode HighQualityBicubic introducing artefacts on edge of resized images ](https://stackoverflow.com/questions/4772273/interpolationmode-highqualitybicubic-introducing-artefacts-on-edge-of-resized-im)
Author
Owner

@NickeManarin commented on GitHub (Sep 1, 2020):

With the next version, Fant and NearestNeighbor were added.

For others algorithms, they need to be implemented manually.

<!-- gh-comment-id:684880521 --> @NickeManarin commented on GitHub (Sep 1, 2020): With the next version, Fant and NearestNeighbor were added. For others algorithms, they need to be implemented manually.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ScreenToGif#1688
No description provided.