• Welcome to Vampyre Imaging Library Forum. Please login or sign up.
 

How to fade-in image with TPaintBox

Started by cocopascal, 17 April 2010, 17:16:47

Previous topic - Next topic

cocopascal

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.

Galfar

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;

cocopascal

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.

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Name:
Email:

Shortcuts: ALT+S save/post or ALT+P preview

SMF spam blocked by CleanTalk