Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi Ähnliche Farben (https://www.delphipraxis.net/36808-aehnliche-farben.html)

delphi_newbie_123 26. Dez 2004 11:43


Ähnliche Farben
 
Hi,
sorry für den Threadnamen, mir ist leider kein besserer eingefallen.
Ich habe einen bestimmten Farbwert und möchte auch ähnliche Farbwerte bei einer Bedingung zulassen.
Wie kann cih dies Bewerkstelligen ohne jede Farbe von Hand einzufügen ? :(
Danke schonmal im Vorraus!!

Oxmyx 26. Dez 2004 12:12

Re: Ähnliche Farben
 
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;

delphi_newbie_123 26. Dez 2004 12:25

Re: Ähnliche Farben
 
danke!!!!


Alle Zeitangaben in WEZ +1. Es ist jetzt 05:41 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz