Fade out a bitmap (Views: 100)


Fade out a bitmap


Put a TImage and load a bitmap of 24 bits  or 32 bits, put a TButton on the form and this code in its OnClick event

procedure TForm1.Button1Click(Sender: TObject);
  procedure FadeOut(const BMP: TImage; Pause: integer);
    BytesPorScan: integer;
    w, h: integer;
    p: pByteArray;
    counter: integer;
    { 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.');

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

    { Decrease the RGB components of each single pixel }
    for counter := 1 to 256 do
      for h := 0 to BMP.Picture.Bitmap.Height - 1 do
        P := BMP.Picture.Bitmap.ScanLine[h];
        for w := 0 to BytesPorScan - 1 do
          if P^[w] > 0 then
            P^[w] := P^[w] - 1;
  end; {procedure FadeOut}

  FadeOut(Image1, 5);

<< Back to main page