The Fade program shows how to use the ScanLine property with a 24-bit Bitmap to "fade out" or to "fade in" an image in a number of steps..
Materials and Equipment
Delphi 3/4/5 (to recompile)
Best when run on 800 x 600 pixel (or higher) monitor in high color or true color mode. Colors will not be very good in the 256 color mode.
The FormCreate routine creates a BitmapBase that is used until the program is terminated.
The ButtonDrawClick displays the "Daisy" image on the BitmapBase.
32 steps are used to fade an image "in" or "out." For each of these 32 steps, each pixel (FOR each "j" ScanLine row FOR each "i" pixel) is manipulated. Each R, G, B pixel value is multiplied by step and divided by 32. For fading an image out, the step ranged from 32 to 0, this was equivalent to multiplying by a linear factor from 1.0 to 0.0. The opposite was true for fading in an image. Step ranged from 0 to 32. The multiplier was effectively 0.0 to 1.0. (The routine MulDiv, from the Windows unit, might be effective here, but was not used.)
There is little or no flicker when fading a small image. However, there is a slight flicker when fading a nearly full-screen image. How to eliminate this flicker is still an open question.
API calls, InvalidateRect and RedrawWindow, were used in the ButtonFadeOutClick method, while the VCL method Repaint was used in the ButtonFadeInClick method.
Palette animation is not possible with 24-bit bitmaps in high color or true color modes. That is, palette animate "tricks" only work with a palette device in 256-color mode.
See also the Tween Lab Report.
Images can be faded in or out relatively well using the Delphi ScanLine property (which was new in Delphi 3). However, a slight flicker is present when fading very large images.
Also see, "HarmFade," which is Graphic/animation component that will transition from one TPicture to another TPicture. It will do either a blend or a dissolve transition. It is easy to use, just assign pictures like you would for a TImage, and in your code use the HarmFade.Blend or HarmFade.Dissolve method to start the effect. It's also sometimes called a 'tweener.'
ScanLine, TRGBTripleArray, SHR, InvalidateRect, RedrawWindow, Repaint
Delphi 3/4/5 Source and EXE (116 KB): Fade.ZIP (updated 26 March 2000)
Thanks to Robert Rossmair, http//:home.t-online.de/home/Robert.Rossmair, for helpful comments about a bug in the original program. (26 March 2000)
Updated 10 August 2002
since 1 Nov 1998