![]() |
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
![]()
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; ![]() Berechnung der Helligkeit:
Delphi-Quellcode:
Berechnung der Sättigung:
Maximum := Max(Red, Max(Green, Blue));
// any other code here... ;-) Brightness := Maximum;
Delphi-Quellcode:
Zitat von
Saturation := MulDiv(Maximum - Minimum, 255, Maximum)
![]() Zitat:
MfG Florian :hi: |
Alle Zeitangaben in WEZ +1. Es ist jetzt 13:55 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz