Title: How to get the transparency color
interface
{------------------------------------------------------------------------------}
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
{------------------------------------------------------------------------------}
function GetByte(Value : TColor; Shift : byte): byte;
{------------------------------------------------------------------------------}
procedure ColorToRGB(Color : TColor; var R, G, B : byte);
{------------------------------------------------------------------------------}
function RGBToColor(R, G, B : byte): TColor;
{------------------------------------------------------------------------------}
function TransparencyColor(BGColor, FRColor : TColor; TranspValue : byte): TColor;
{------------------------------------------------------------------------------}
implementation
function GetByte(Value : TColor; Shift : byte): byte;
begin
Result := (Value and ($FF shl Shift)) shr Shift;
end;
{------------------------------------------------------------------------------}
procedure ColorToRGB(Color : TColor; var R, G, B : byte);
begin
R := GetByte(Color, 16); //zweites Byte aus Color (v.R.)
G := GetByte(Color, 8); //drittes Byte aus Color (v.R.)
B := GetByte(Color, 0); //viertes Byte aus Color (v.R.)
end;
{------------------------------------------------------------------------------}
function RGBToColor(R, G, B : byte): TColor;
begin
Result := ((R and $FF) shl 16) +
((G and $FF) shl 8) + (B and $FF);
end;
{------------------------------------------------------------------------------}
function TransparencyColor(BGColor, FRColor : TColor; TranspValue : byte): TColor;
var
BGR, BGG, BGB, FRR, FRG, FRB, ergR, ergG, ergB : byte;
TrFact : real;
begin
TrFact := TranspValue / 100;
ColorToRGB(BGColor, BGR, BGG, BGB);
ColorToRGB(FRColor, FRR, FRG, FRB);
ergR := byte(Trunc(BGR * TrFact + FRR * (1 - TrFact)));
ergG := byte(Trunc(BGG * TrFact + FRG * (1 - TrFact)));
ergB := byte(Trunc(BGB * TrFact + FRB * (1 - TrFact)));
Result := RGBToColor(ErgR, ergG, ergB);
end;
{------------------------------------------------------------------------------}