TTeeFilter

TTeeFilter
Hierarchy     Properties     Methods     Events     

Unit
TeCanvas

Description
Base abstract class for all image "Filters".

A TeeFilter class implements image manipulation at the pixel level, such as Blur, Contrast, Brightness and so on.

See TeeFilters unit for a list of filters.

The Filter Editor dialog allows adding, configuring and removing filters for a specific image property, both at design-time and run-time.

New filter classes can be easily implemented by deriving from TTeeFilter class or any other filter class.
For example, the following code implements a new filter class to "invert" all pixels of a bitmap:

type
TInvertFilter=class(TTeeFilter)
public
procedure Apply(Bitmap:TBitmap; const R:TRect); override;
class function Description: String; override;
end;

The Apply method does the job of inverting all pixels in the Bitmap image of a given rectangle area:

procedure TInvertFilter.Apply(Bitmap:TBitmap; const R:TRect);
var x,y : Integer;
begin
inherited;

if Length(Lines)=0 then
Exit;

for y:=R.Top to R.Bottom do
for x:=R.Left to R.Right do
with Lines[y,x] do
begin
Blue:=255-Blue;
Green:=255-Green;
Red:=255-Red;
end;
end;


The Description function returns a string that identifies the filter class, to show at filters editor dialog:

class function TInvertFilter.Description: String;
begin
result:='Invert';
end;

To show this filter class at design and runtime at the filters editor dialog you should first "register" the filter using the following procedure:

initialization
TeeRegisterFilters([ TInvertFilter ]);
finalization
TeeUnRegisterFilters([ TInvertFilter ]);

It is recommended to register filters at the initialization of your units, but not mandatory.
Registered filters are kept at public global variable FilterClasses (of type TList) in TeeFilters unit.

To use the filter class you can use the quick way of a class method that automatically creates and destroys the filter instance, for example:

TInvertFilter.ApplyTo(MyBitmap);

or you can create the filter instance and call the Apply method:

var i : TInvertFilter;
i:=TInvertFilter.Create(nil);
i.Apply(MyBitmap);
i.Free;

You can add new properties, events, constructors and methods to a filter class like any other class.

Filter classes can show a custom editor dialog to modify their properties.
This is accomplished by overriding the CreateEditor virtual method.