我这里有一个淡入淡出的程序,把关键的部分贴上,你自己看吧,希望对你有帮助。
procedure TFormDaisy.ButtonFadeOutClick(Sender: TObject);
VAR
Bitmap : TBitmap;
i : INTEGER;
j : INTEGER;
Row : pRGBTripleArray;
RowBase: pRGBTripleArray;
step : INTEGER;
begin
Bitmap := TBitmap.Create;
TRY
Bitmap.PixelFormat := pf24bit;
Bitmap.Width := ImageRGB.Width;
Bitmap.Height := ImageRGB.Height;
FOR step := 32 DOWNTO 0 DO
BEGIN
FOR j := 0 TO Bitmap.Height-1 DO
BEGIN
RowBase := BitmapBase.Scanline[j];
Row := Bitmap.Scanline[j];
FOR i := 0 TO Bitmap.Width-1 DO
BEGIN // 32 = 2^5
Row[i].rgbtRed := (step * RowBase[i].rgbtRed ) SHR 5;
Row[i].rgbtGreen := (step * RowBase[i].rgbtGreen) SHR 5;
Row[i].rgbtBlue := (step * RowBase[i].rgbtBlue ) SHR 5
END
END;
ImageRGB.Picture.Graphic := Bitmap;
// Use API calls to avoid flicker.
// See VCL Repaint alternative in FadeIn
InvalidateRect(FormDaisy.Handle, NIL {whole window},
FALSE {don't erase background});
RedrawWindow(FormDaisy.Handle, NIL, 0, RDW_UPDATENOW);
END
FINALLY
Bitmap.Free;
END;
end;
procedure TFormDaisy.ButtonFadeInClick(Sender: TObject);
VAR
Bitmap : TBitmap;
i : INTEGER;
j : INTEGER;
Row : pRGBTripleArray;
RowBase: pRGBTripleArray;
step : INTEGER;
begin
Bitmap := TBitmap.Create;
TRY
Bitmap.PixelFormat := pf24bit;
Bitmap.Width := ImageRGB.Width;
Bitmap.Height := ImageRGB.Height;
FOR step := 0 TO 32 DO
BEGIN
FOR j := 0 TO Bitmap.Height-1 DO
BEGIN
RowBase := BitmapBase.Scanline[j];
Row := Bitmap.Scanline[j];
FOR i := 0 TO Bitmap.Width-1 DO
BEGIN // 32 = 2^5
Row[i].rgbtRed := (step * RowBase[i].rgbtRed ) SHR 5;
Row[i].rgbtGreen := (step * RowBase[i].rgbtGreen) SHR 5;
Row[i].rgbtBlue := (step * RowBase[i].rgbtBlue ) SHR 5
END
END;
// This is just as effective as the API calls.
// (See API call alternative in FadeOut.)
ImageRGB.Picture.Graphic := Bitmap;
ImageRGB.Repaint
END
FINALLY
Bitmap.Free;
END;
end;