这下是问题大了,我不敢结呀,这是在技术区!
算了,贴一段Alpha混合算法:
procedure AlphaBlend(DestBitmap, SourceBitmap: TBitmap;
ARect: TRect; BlendScale: Byte);
var
Source, Dest: ^Cardinal;
x, y: Integer;
C, CBRB, CBG: Cardinal;
TmpRect, MidRect: TRect;
StoreP: TPoint;
begin
if (DestBitmap = nil) or (SourceBitmap = nil) then exit;
with TmpRect, DestBitmap do
begin
TopLeft := Point(0, 0);
Bottom := Height;
Right := Width;
end;
if not InterSectRect(TmpRect, TmpRect, ARect) then exit;
with MidRect, SourceBitmap do
begin
TopLeft := Point(0, 0);
Bottom := Height;
Right := Width;
end;
if not InterSectRect(TmpRect, TmpRect, MidRect) then exit;
if DestBitmap.PixelFormat <> pf32bit then
DestBitmap.PixelFormat := pf32bit;
if SourceBitmap.PixelFormat <> pf32bit then
SourceBitmap.PixelFormat := pf32bit;
{$WARNINGS OFF}
with TmpRect do
case BlendScale of
255:
for y := Top To Bottom - 1 do
begin
Source := SourceBitmap.ScanLine[y];
Dest := DestBitmap.ScanLine[y + StoreP.y];
Move(Source^, Dest^, (Right - Left) * SizeOf(Cardinal));
end;
0:;
else
for y := Top to Bottom - 1 do
begin
Source := SourceBitmap.ScanLine[y];
Dest := DestBitmap.ScanLine[y + StoreP.Y];
Inc(Dest, StoreP.X);
for x := Left to Right do
begin
if Source^ <> Dest^ then
begin
CBRB := (Dest^ and $00FF00FF) * (255 - BlendScale);
CBG := (Dest^ and $0000FF00) * (255 - BlendScale);
C := ((Source^ and $00FF00FF) * BlendScale + CBRB) and $FF00FF00 +
((Source^ and $00FF00) * BlendScale + CBG) and $00FF0000;
Dest^ := C shr 8;
end;
Inc(Source);
Inc(Dest);
end;
end;
end;
{$WARNINGS ON}
end;