Napisałem sobie takie funkcje do alphablendingu:
function getalphacolor(Background, Foreground: TColor;
Alpha: byte): TColor;
begin
Result:=rgb(round((Alpha/100)*GetRValue(Foreground)+(1-(Alpha/100))*GetRValue(Background)), round((Alpha/100)*GetGValue(Foreground)+(1-(Alpha/100))*GetGValue(Background)), round((Alpha/100)*GetBValue(Foreground)+(1-(Alpha/100))*GetBValue(Background)));
end;
function getalphabitmap(Background, Foreground:TBitmap; X, Y:Integer; Alpha:Byte; Offset:Integer):TBitmap;
var
a, b, tmp:integer;
begin
result:=tbitmap.Create;
result.Width:=foreground.Width;
result.Height:=foreground.Height;
for a:=0 to foreground.Width do
for b:=0 to foreground.Height do
if (a+x<=background.Width) and (b+y<=background.Height) then
begin
if a<=offset then
tmp:=round(a/offsetalpha);
if a>=foreground.Width-offset then
tmp:=round((foreground.Width-a)/offsetalpha);
if (a>offset) and (a<foreground.Width-offset) then
tmp:=alpha;
result.Canvas.Pixels[a, b]:=getalphacolor(background.Canvas.Pixels[a+x, b+y], foreground.Canvas.Pixels[a, b], tmp);
end;
I wszystko działa ładnie, tylko że bardzo wolno (przy ciągłym odświeżaniu). Czy nie ma jakiegoś szybszego sposobu? I jeszcze jeden, poważniejszy problem. Po kilku minutach wywooływania tego co 50 ms zaczyna wyskakiwać błąd 'Out of system resources'. Podejrzewam, że przyczyną jest niezwalnianie bitmapy będącej rezultatem funkcji, nie wiem niestety, jak to naprawić.---------------------------
Delphi 6
Pozdrówka