Author Topic: How to fade-in image with TPaintBox  (Read 962 times)

Offline cocopascal

  • Imaging User
  • *
  • Posts: 7
    • View Profile
How to fade-in image with TPaintBox
« on: 17 April 2010, 17:16:47 »
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.

Offline Galfar

  • Administrator
  • Imaging User
  • *****
  • Posts: 312
    • View Profile
    • Galfar's Homepage
Re: How to fade-in image with TPaintBox
« Reply #1 on: 20 April 2010, 16:38:23 »
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.

Code: [Select]
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;

Offline cocopascal

  • Imaging User
  • *
  • Posts: 7
    • View Profile
Re: How to fade-in image with TPaintBox
« Reply #2 on: 3 May 2010, 10:18:43 »
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.