Die Mischfarbe zweier Farben berechnen
Folgende Routine berechnet die Mischfarbe zweier Farben unter Angabe eines Transparenzwertes (0-100):
Delphi-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24:
| function MixColor(Color1, Color2 : TColor; AlphaBlendValue : byte) : TColor; var b1,b2,b3,r1,r2,r3,g1,g2,g3: byte; begin if AlphaBlendValue > 100 then AlphaBlendValue := 100; b1:=GetBValue(Color1); b2:=GetBValue(Color2); b3:=round((AlphaBlendValue/100)*b1 + (1-AlphaBlendValue/100)*b2);
r1:=GetRValue(Color1); r2:=GetRValue(Color2); r3:=round((AlphaBlendValue/100)*r1 + (1-AlphaBlendValue/100)*r2);
g1:=GetGValue(Color1); g2:=GetGValue(Color2); g3:=round((AlphaBlendValue/100)*g1 + (1-AlphaBlendValue/100)*g2);
result:=RGB(r3,g3,b3); end; |
Beispielaufruf:
Delphi-Quelltext
1:
| MixColor(clBlue, clRed, 50); |
Moderiert von Christian S.: Parametererklärungen und Beispiel eingefügt
_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot