ImageKit has three classes that support image processing:

  • TIKFilter is a mutable object that represents an effect. A filter object has at least one input parameter and produces an output image.

  • TIKImage is an immutable object that represents an image. You can synthesize image data or provide it from a file or the output of another TIKFilter object.

  • TIKContext is an object through which ImageKit draws the results produced by a filter.

The remainder of this chapter provides all the details you need to use ImageKit filters and the TIKFilter, TIKImage, and TIKContext classes.

The basics of applying a filter to an image

Img := TIKImage.CreateWithFile('myfile.jpg')
Filter := TIKFilter.CreateWithName('GaussianBlur');
Filter.SetValue('InputImage', Img);
Filter.SetValue('InputRadius', 10);
Image1.Picture.Assign(Filter.OutputImage);

Here’s what the code does:

  1. Create a TIKmage object. You can create a TIKImage from a variety of sources, such as a file, TBitmap object, TGPBitmap object or raw bitmap data.

  2. Create the filter and set values for its input parameters. There are more compact ways to set values than shown here.

  3. Get the output image and assign to VCL TImage.Picture object. You can assign TIKImage or draw it using TIKContext object.
The Built-in Filters
ImageKit comes with bunch of built-in filters ready to support image processing in your app. The list of built-in filters can change, so for that reason,Imagekit provides methods that let you query the system for the available filters as part of TIKFilter class - TIKFilter.FilterNames, TIKFilter.FilterCategories, TIKFilter.FilterNamesInCategory.

Most filters have one or more input parameters that let you control how processing is done. You can change input parameters using SetValue method.

Chaining Filters
You can create amazing effects by chaining filters—that is, using the output image from one filter as input to another filter. Let's show how it works on built-in Glow filter:

function TIKGlowFilter.GetOutputImage: TIKImage;
begin
  FBlur.InputImage := InputImage;
  FBlur.InputRadius := InputRadius;

  FCrop.InputImage := InputImage;
  FCrop.InputRect := FBlur.OutputImage.Extent;

  FMonochrome.InputImage := FBlur.OutputImage;
  FMonochrome.InputColor := FInputColor;
  FMonochrome.InputIntensity := FInputIntensity;

  FBlend.InputImage := FCrop.OutputImage;
  FBlend.InputBackgroundImage := FMonochrome.OutputImage;

  Result := FBlend.OutputImage;
end;

Here’s what the code does:

  1. Start from GaussianBlur filter to get blured image

  2. Adds Crop filter to make InputImage extent the same as blured

  3. Adds Monochrome filter to make glow image monochrome

  4. Adds SourceOverCompositing filter to compose two images

  5. Return reuslt of latest filter