Autor Beitrag
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Fr 16.02.07 19:00 
Die Mischfarbe zweier Farben berechnen

Folgende Routine berechnet die Mischfarbe zweier Farben unter Angabe eines Transparenzwertes (0-100):
ausblenden 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:
//Berechnet die Mischfarbe zweier Farben unter Angabe eines Transparenzwertes (0-100)
//Parameter:
//  Color1: Hintergrundfarbe
//  Color2: Vordergrundfarbe
//  AlphaBlendValue: Transparenz der Vordergrundfarbe im Bereich von 0..100 (0 = vollständig deckend)
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//Zur Verhinderung eines Überlaufs

  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:
ausblenden Delphi-Quelltext
1:
MixColor(clBlue, clRed, 50); //Blau mit einem 50% deckenden Rot überlagern					


Moderiert von user profile iconChristian 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


Zuletzt bearbeitet von Marco D. am Fr 16.02.07 19:14, insgesamt 2-mal bearbeitet