Vampyre Imaging Library Forum

Imaging Category => Help & Questions => Topic started by: cocopascal on 17 April 2010, 17:16:47

Title: How to fade-in image with TPaintBox
Post by: cocopascal 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.
Title: Re: How to fade-in image with TPaintBox
Post by: Galfar 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.


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;
Title: Re: How to fade-in image with TPaintBox
Post by: cocopascal 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.