Thema: Delphi Ähnliche Farben

Einzelnen Beitrag anzeigen

Oxmyx

Registriert seit: 21. Sep 2004
499 Beiträge
 
#2

Re: Ähnliche Farben

  Alt 26. Dez 2004, 12:12
Ich habe mal schnell eine Funktion geschrieben:

Delphi-Quellcode:
const
  CF_RED = 1;
  CF_GREEN = 2;
  CF_BLUE = 4;
  CF_ALL = 8;

type
  TColorBytes = record
    r, g, b, a: Byte;
  end;


function IsColorSimilar(Color1, Color2: TColor;
                        ColorFlags: DWORD;
                        MaxDifference: Byte): BOOL;
var
  ColorBytes1, ColorBytes2: TColorBytes;
begin
  Result := FALSE;

  ColorBytes1 := TColorBytes(Color1);
  ColorBytes2 := TColorBytes(Color2);

  if (ColorFlags and CF_ALL) <> 0 then
    ColorFlags := CF_RED or CF_GREEN or CF_BLUE;

  if (ColorFlags and CF_RED) <> 0 then
    if abs(ColorBytes1.r - ColorBytes2.r) > MaxDifference then Exit;

  if (ColorFlags and CF_GREEN) <> 0 then
    if abs(ColorBytes1.g - ColorBytes2.g) > MaxDifference then Exit;

  if (ColorFlags and CF_BLUE) <> 0 then
    if abs(ColorBytes1.b - ColorBytes2.b) > MaxDifference then Exit;

  Result := TRUE;
end;
  Mit Zitat antworten Zitat