title: How could I fade in/out a TImage?
body: <p>I have a simple <code>TForm</code> named Form1; Image1 which is a <code>TImage</code> loaded with a PNGImage and a Button1 <code>TButton</code> to test things. It was implemented sucessfully a method to AlphaBlend Image1's picture. Code follows:</p>
  
  <pre><code>procedure SetPNGOpacity(Image : TImage; Alpha: Byte);
  var
      Bmp: TBitmap;
      BlendFn: TBlendFunction;
      PNG: TPNGImage;
  begin
      Png := TPngImage.Create;
      Png.Assign(TPNGImage(Image.Picture.Graphic));
      Bmp := TBitmap.Create;
      Bmp.Assign(Png);
      Image.Picture.Bitmap.PixelFormat := pf32bit;
      Image.Picture.Bitmap.AlphaFormat := afPremultiplied;
      Image.Picture.Bitmap.Canvas.Brush.Color := clBlack;
      Image.Picture.Bitmap.SetSize(Png.Width, Png.Height);
      BlendFn.BlendOp := AC_SRC_OVER;
      BlendFn.BlendFlags := 0;
      BlendFn.SourceConstantAlpha := Alpha;
      BlendFn.AlphaFormat := AC_SRC_ALPHA;
      winapi.windows.AlphaBlend(
          Image.Picture.Bitmap.Canvas.Handle,
          0, 0, Image.Picture.Bitmap.Width,
          Image.Picture.Bitmap.Height,
          Bmp.Canvas.Handle,
          0, 0, Bmp.Width,
          Bmp.Height,
          BlendFn
      );
      Bmp.FreeImage;
      Bmp.Free;
      Png.Free;
  end;
  </code></pre>
  
  <p>If I simple calls this on the Button1 <code>onClick</code> the Image is blended.
  My goal anyway is to Fade In/Out Image1; or in other words, go to Opacity 0 to 255 and inverse way. What I could see is that the <code>SetPNGOpacity</code> up there stop working inside a Loop.
  I naturaly tried set the application busy with the following code:</p>
  
  <pre><code>procedure TForm1.Button1Click(Sender: TObject);
  var 
      I : integer;
  begin
      I := 255;
      while I &gt; 0 do
      begin
          I := I - 1;
          sleep(125);
          SetPNGOpacity(Image2, I);
     //     MessageBeep(0);
      end;
  end;
  </code></pre>
  
  <p>I was just expecting to wait some seconds with a inactive window and then Image1 should desappear completelly. What did not happen. So I tried it with a simple thread to Fade Out, descripted here:</p>
  
  <pre><code>TBar = class(TThread)
  private
      I : integer;
  public
      procedure execute; override;
      procedure Test;
      constructor Create;
  end;
  
  implementation
  
  constructor TBar.Create;
  begin
      inherited Create(false);
      I := 255;
  end;
  
  procedure TBar.execute;
  begin
      while I &gt; 0 do
      begin
          I := I - 1;
          sleep(250);
          synchronize(Test);
       //   MessageBeep(0);
      end;
  end;
  
  procedure TBar.Test;
  begin
      SetPNGOpacity(Form1.Image2, I);
  end;
  </code></pre>
  
  <p>And call it like this:</p>
  
  <pre><code>procedure TForm1.Button1Click(Sender: TObject);
  var 
      Foo : TBar;
  begin
      Foo := TBar.Create;
  end;
  </code></pre>
  
  <p>Again, nothing happens. So I need you guys again. Someone have an idea about it? Am I doing something wrong? Does anyone know some useful reading; or even a helpful piece of code? Note: I really wish it would be using <code>TImage</code> or even a <code>TBitmap</code> which I could "extract/store" in a <code>TImage</code>.</p>
  
  <p>Thanks in advance.</p>