Recent Changes - Search:

Support

Site

Links

FAQ /

Resampling

<< Image format related | Frequently asked questions | Miscellaneous >>

1. Where did the stretch filters go in Graphics32 1.8?

Stretch filters have been replaced with resamplers in Graphics32 1.8. This means that you can't switch between different resampling methods simply by changing the StretchFilter property of a TBitmap32 instance.

The introduction of resampler classes was an attempt to make Graphics32 more flexible and to allow custom resampling methods to be implemented without patching the existing codebase.

2. Can I still use stretch filters in Graphics32 1.8?

Yes, by defining the conditional symbol $DEPRECATEDMODE in the file GR32.INC, stretch filters may still be used. However, from Graphics32 1.8 this is considered obsolete and it may not be supported in future versions.

3. What is a resampler and how do I use it?

A resampler is a special class derived from TCustomResampler. It provides a method for reconstructing pixels when an image is scaled. Each TBitmap32 object has its own dedicated resampler, accessible through the Resampler property.

Currently four different resampler classes have been implemented in Graphics32:

Class name

Resampling quality

Performance

TNearestResampler

low

high

TDraftResampler

medium

high (downsampling only)

TLinearResampler

medium

medium

TKernelResampler

high

low (depends on kernel width)

As can be seen from the above table, there is always a trade-off between quality and performance when choosing a resampler. While TNearestResampler is fast, it gives a very poor result. Contrary, TKernelResampler gives a high quality result at the expense of a degraded performance.

Example 1: Given a TBitmap32 object B, how do we set its resampler to TDraftResampler? The most straight-forward way to do this would be as follows:

TDraftResampler.Create(B);

Example 2: Suppose that we want to resize the source bitmap Src by drawing it onto the destination bitmap Dst. We want to use TKernelResampler and we want to use TLanczosKernel as a reconstruction filter (also known as a convolution kernel). This could be done as follows:

procedure DrawSrcToDst(Src, Dst: TBitmap32);
var
  R: TKernelResampler;  
begin
  R := TKernelResampler.Create(Src);
  R.Kernel := TLanczosKernel.Create;
  Dst.Draw(Dst.BoundsRect, Src.BoundsRect, Src);
end;
Edit - History - Print - Recent Changes - Search
Page last modified on May 17, 2009, at 04:38 PM