ImageEn, unit imageenproc




function GuessChromaKeyColor() : TRGB; overload;
function GuessChromaKeyColor(out Tolerance: Double) : TRGB; overload;


Analyzes a ChromaKey image to guess its key color (by examining nine areas of the image and using the one with the least hue variance). If a selection is active it only analyzes the selection.

The second overload will return a level of Tolerance that would remove all the background color from the selection. If this is used without a selection it is likely to return a level that is too low (a default tolerance of 0.21 is usually better).

A ChromaKey image contains a solid color block that is removed so that it can be applied to a background. E.g. in the following image the key color is neon green (R=0/G=254/B=0).

Note: If the image PixelFormat is not ie24RGB, it will be converted


Demo  Demos\ImageEditing\ChromaKey\ChromaKey.dpr
Demo  Demos\ImageEditing\EveryMethod\EveryMethod.dpr


// Get the key color of the current layer
ImageEnView1.LayersCurrent := 1;
KeyColor := ImageEnView1.Proc.GuessChromaKeyColor();
clsKeyColor.Color := TRGB2TColor( KeyColor );

// Guess the key color and tolerance of the area selected by the user
procedure TMainForm.ImageEnView1SelectionChange(Sender: TObject);
  Tolerance: Double;
  KeyColor : TRGB;
  if ImageEnView1.Selected then
    KeyColor := ImageEnView1.Proc.GuessChromaKeyColor( Tolerance );
    clsKeyColor.Color := TRGB2TColor( KeyColor );
    trkTolerance.Position := Trunc( Tolerance * 1000 );

See Also

- RemoveChromaKey
- CreateRGB
- TRGB2TColor
- TColor2TRGB