Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Library: Grafik / Sound / Multimedia (https://www.delphipraxis.net/21-library-grafik-sound-multimedia/)
-   -   Delphi RGB to HSV || Sättigung / Helligkeit / Farbton bestimmen (https://www.delphipraxis.net/21076-rgb-hsv-%7C%7C-saettigung-helligkeit-farbton-bestimmen.html)

flomei 27. Apr 2004 18:00


RGB to HSV || Sättigung / Helligkeit / Farbton bestimmen
 
Wer die Helligkeit / Sättigung / den Farbton eines RGB-Farbwertes berechnen möchte dem sei folgender Code aus diesem Thread ans Herz gelegt:
Delphi-Quellcode:
procedure TForm1.RGBtoHSV(Red, Green, Blue: Byte; var Hue: THue; var Saturation, Value: Byte);
var
  Maximum, Minimum: Byte;
  Rc, Gc, Bc: Single;
  H: Single;
begin
  Maximum := Max(Red, Max(Green, Blue));
  Minimum := Min(Red, Min(Green, Blue));
  Value := Maximum;
  if Maximum <> 0 then
    Saturation := MulDiv(Maximum - Minimum, 255, Maximum)
  else
    Saturation := 0;
  if Saturation = 0 then
    Hue := 0 // arbitrary value
  else
  begin
    Assert(Maximum <> Minimum);
    Rc := (Maximum - Red) / (Maximum - Minimum);
    Gc := (Maximum - Green) / (Maximum - Minimum);
    Bc := (Maximum - Blue) / (Maximum - Minimum);
    if Red = Maximum then
      H := Bc - Gc
    else if Green = Maximum then
      H := 2 + Rc - Bc
    else
    begin
      Assert(Blue = Maximum);
      H := 4 + Gc - Rc;
    end;
    H := H * 60;
    if H < 0 then
      H := H + 360;
    Hue := Round(H);
  end;
end;
Klick! DanielJ

Berechnung der Helligkeit:
Delphi-Quellcode:
Maximum := Max(Red, Max(Green, Blue));
// any other code here... ;-)
Brightness := Maximum;
Berechnung der Sättigung:
Delphi-Quellcode:
Saturation := MulDiv(Maximum - Minimum, 255, Maximum)
Zitat von dieser Seite:
Zitat:

|---------------------------|
| HSB |
| Hue Saturation Brightness |
| HSV |
|---------------------------|

Ein Farbmodell, das aus folgenden 3 Koordinaten besteht, die einen Farbkegel bilden:

- Farbton (Hue)
- Sättigung (Saturation)
- Helligkeit (Brightness, Value)

Der Farbton wird als Winkel auf einen Farbkreis angegeben.
Rot = 0 °
Gelb = 60 °
Grün = 120 °
Cyan = 180 °
Blau = 240 °
Magenta = 300 °

Sättigung wird in Prozent angegeben.
0% = keine Farbe (weis bzw. grau)
100% = satte Farbe

Helligkeit wird in Prozent angegeben
0% = dunkel (volle Schwarzbeimischung)100% = hell (keine Schwarzbeimischung)
HTH! ;)

MfG Florian :hi:


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:26 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