I have a slideshow using DisplayImage for drawing on a TPaintBox. Now I want to fade-in/fade-out images. How do I do that?
I tried something like Image.DrawAlpha(Image.BoundsRect, PaintBox.Canvas, 0, 0) in a loop where alphachannel values increases/decreased. It doesn't work.
This is a quick test a put together that works, fades from black to the image and paints onto TPainBox. Be sure to use TFastARGB32Canvas. Also no need to increase alpha by 1, whole fade tooks about 3 seconds on my PC this way.
var
Img, OutImg: TSingleImage;
Canvas, OutCanvas: TImagingCanvas;
I: Integer;
begin
Img := TSingleImage.CreateFromFile('data\Tigers.png');
Img.Format := ifA8R8G8B8;
Canvas := TFastARGB32Canvas.CreateForImage(Img);
OutImg := TSingleImage.CreateFromImage(Img);
OutCanvas := TFastARGB32Canvas.CreateForImage(OutImg);
OutCanvas.FillColor32 := pcBlack;
OutCanvas.Clear;
I := 0;
Canvas.FillChannel(ChannelAlpha, I);
while I <= 255 do
begin
OutCanvas.Clear;
Canvas.FillChannel(ChannelAlpha, I);
Canvas.DrawAlpha(Img.BoundsRect, OutCanvas, 0, 0);
DisplayImage(PaintBox.Canvas, 0, 0, OutImg);
Inc(I, 1);
end;
end;
I got an invalid image error with the png image. jng worked fine, thank you.
The show is running on a minipc with Intel Celeron M 373 @ 1000 Mhz and a HP LP2475w 1200x1920 px monitor. Fading in from alpha 20 to 255 in 30 steps takes about 6 seconds, showing also horizontally moving stripes.