这是我写的一个函数,只能将两副画分成16部进行淡出
DHd为目标图的handle,SHd为源图的handle,其他为坐标
procedure Fade(DHd,x,y,width,height,SHd,Sx,Sy:integer);
type ByteArray=array[0..0] of Byte;
SIntArray=Array[0..0] of SmallInt;
var Count,i,step : Integer;
DImg : TBitmap;
PDbit,PSbit : ^byteArray;
PDif : ^SIntArray;
begin
DImg:=TBitmap.Create;
Count:=Height*Width*3;
DImg.PixelFormat:=pf24bit;
DIMg.Width:=Width;
DImg.Height:=Height;
GetMem(PSbit,Count);
GetMem(PDbit,Count);
GetMem(PDif,Count*2);
BitBlt(DImg.Canvas.Handle,0,0,Width,Height,DHD,x,y,SRCCOPY);
Getbitmapbits(DImg.Handle,Count,PDBit);
BitBlt(DImg.Canvas.Handle,0,0,Width,Height,SHD,Sx,Sy,SRCCOPY);
Getbitmapbits(DImg.Handle,Count,PSBit);
For i:=0 to Count-1 do
PDif^:=(PSbit^-PDbit^);
for Step:=1 to 15 do
begin
For i:=0 to Count-1 do
PSbit^:=PDbit^+(Pdif^*Step) shr 4;
SetBitmapBits(DImg.handle,Count,PSbit);
BitBlt(DHD,x,y,Width,Height,DImg.Canvas.Handle,0,0,SRCCOPY);
sleep(100);
End;
BitBlt(DHD,x,y,Width,Height,SHD,SX,SY,SRCCOPY);
FreeMem(PDif,Count*2);
FreeMem(PSBit,Count);
FreeMem(PDBit,Count);
DImg.Free;
end;