//让图渐显
function DrawFadeIn (const OriginBmp : TBitmap ; Image : TImage ;
const GrayParam : Byte; const ParentHandle: Integer ) : boolean ;
var
tmpBmp : TBitmap;
Row, BaseRow : pRGBTripleArray;
x, y, Step : Integer;
OffSet : Byte ;
begin
Result := false ;
if not (OriginBmp.PixelFormat in [pf24Bit, pf32Bit]) then exit ;
tmpBmp := TBitmap.Create;
tmpBmp.PixelFormat := OriginBmp.PixelFormat ;
OffSet := GrayParam ;
try
tmpBmp.Assign(OriginBmp) ;
for Step := Trunc(Power(2,OffSet)) - GrayParam to Trunc(Power(2,OffSet)) do
begin
for y := 0 to (tmpBmp.Height - 1) do
begin
BaseRow := OriginBmp.Scanline[y];
Row := tmpBmp.Scanline[y];
for x := 0 to (tmpBmp.Width - 1) do
begin
Row[x].rgbtRed := (Step * BaseRow[x].rgbtRed) shr OffSet ;
Row[x].rgbtGreen := (Step * BaseRow[x].rgbtGreen) shr OffSet ;
Row[x].rgbtBlue := (Step * BaseRow[x].rgbtBlue) shr OffSet ;
end;
end;
Image.Canvas.Draw(0,0,tmpBmp); //这样画效率好象高一点,但会出现上图残留
InvalidateRect(ParentHandle, nil, false);
RedrawWindow(ParentHandle, nil, 0,RDW_UPDATENOW);
end;
finally
tmpBmp.Free ;
tmpBmp := nil ;
end;
Result := true ;
end;