TImage.Bitmap fade out

106 79
< Continued from page 2

Put a TImage (Image1) on a Delphi form and load a bitmap of 24 bits or 32 bits in it; put a TButton (Button1) and put this code in its OnClick event:

~~~~~~~~~~~~~~~~~~~~~~~~~
procedure TForm1.Button1Click(Sender: TObject) ;

  procedure FadeOut(const BMP:TImage; Pause:integer) ;
   var
    BytesPorScan : integer;
    w,h : integer;
    p : pByteArray;
    counter : integer;

   begin
      {This only works with 24 or 32 bits bitmaps}
      If Not (BMP.Picture.Bitmap.PixelFormat
              in [pf24Bit, pf32Bit])
       then raise exception.create
          ('Error, bitmap format not supported.') ;

      try
       BytesPorScan:=
        Abs(Integer(BMP.Picture.Bitmap.ScanLine[1])-
            Integer(BMP.Picture.Bitmap.ScanLine[0])) ;
      except
        raise exception.create('Error') ;
      end;

      {Decrease the RGB for each single pixel}
      for counter:=1 to 256 do
      begin
        for h:=0 to BMP.Picture.Bitmap.Height-1 do
        begin
          P:=BMP.Picture.Bitmap.ScanLine[h];
          for w:=0 to BytesPorScan-1 do
            if P^[w] >0 then P^[w]:=P^[w]-1;
        end;
        Sleep(Pause) ;
      BMP.Refresh;
      end;
    end; {procedure FadeOut}
  begin {button1_click}
    FadeOut(Image1,5) ;
  end;
~~~~~~~~~~~~~~~~~~~~~~~~~


Delphi tips navigator:
» How to set margins in Memo
« Change the Windows Start button bitmap

Source...
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.