Thema: Delphi Farbpalette erstellen?

Einzelnen Beitrag anzeigen

neolithos

Registriert seit: 31. Jul 2003
Ort: Dresden
1.386 Beiträge
 
Delphi 7 Architect
 
#9

Re: Farbpalette erstellen?

  Alt 16. Feb 2004, 14:59
Delphi-Quellcode:
procedure TForm1.cmdRGBtoHSVClick(Sender: TObject);
var iDelta,
    iMax,
    iMin,
    h, s, v : Double;
    r, g, b : Byte;
begin
  r := StrToInt(txtR.Text);
  g := StrToInt(txtG.Text);
  b := StrToInt(txtB.Text);


  iMax := MaxIntValue([R, G, B]);
  iMin := MinIntValue([R, G, B]);
  iDelta := iMax - iMin;
  h := 0;
  if iDelta > 0 then
     begin
       if r = iMax then h := (b - g) / iDelta;
       if b = iMax then h := (g - r) / iDelta + 2;
       if g = iMax then h := (r - b) / iDelta + 4;
     end;
  h := h * 60;
  if h < 0 then h := h + 360;
  if iMax = 0 then
     s := 0
  else
     s := iDelta / iMax;
  v := iMax / 255;

  txtH.Text := FloatToStr(h);
  txtS.Text := FloatToStr(s);
  txtV.Text := FloatToStr(v);
end;

const
  cdwKreis : array [0..5] of Cardinal = ($0000FF, $FF00FF, $FF0000,
    $FFFF00, $00FF00, $00FFFF);

procedure TForm1.cmdHSVtoRGBClick(Sender: TObject);
var iColor,
    iNext : Integer;
    dwColor : Cardinal;
    fDelta,
    h, s, v : Double;
begin
  h := StrToFloat(txtH.Text);
  s := StrToFloat(txtS.Text);
  v := StrToFloat(txtV.Text);

  iColor := Trunc(h / 60);
  fDelta := Frac(h / 60);

  if iColor = 5 then
     iNext := 0
  else
     iNext := iColor + 1;
  dwColor := GetMixColor(cdwKreis[iColor], cdwKreis[iNext], fDelta);
  dwColor := GetMixColor(dwColor, $FFFFFF, 1 - s);
  dwColor := GetMixColor(dwColor, 0, v);

  txtR.Text := IntToStr(GetRValue(dwColor));
  txtG.Text := IntToStr(GetGValue(dwColor));
  txtB.Text := IntToStr(GetBValue(dwColor));
end;
Vielleicht hilft das ja weiter...
- ciao neo -
Es gibt niemals dumme Fragen, sondern nur dumme Antworten!
  Mit Zitat antworten Zitat