title: How to create transparent png image from bitmap?
body: <p>My task is:</p>
  
  <ol>
  <li>Create a TBitmap object.</li>
  <li>Fill it with transparent color (alpha = 0).</li>
  <li>Assign this bitmap to TPngImage.</li>
  <li>Save PNG file with alpha transparency.</li>
  </ol>
  
  <p>How can I do it in Delphi XE?</p>
  
  <pre><code>var
    Png: TPngImage;
    X, Y: Integer;
    Bitmap: TBitmap;
  begin
    Bitmap := TBitmap.Create();
    Bitmap.PixelFormat := pf32bit;
    Png := TPngImage.Create();
    try
      Bitmap.SetSize(100, 100);
  
      // How to clear background in transparent color correctly?
      // I tried to use this, but the image in PNG file has solid white background:
      for Y := 0 to Bitmap.Height - 1 do
        for X := 0 to Bitmap.Width - 1 do
          Bitmap.Canvas.Pixels[X, Y]:= $00FFFFFF;
  
      // Now drawing something on a Bitmap.Canvas...
      Bitmap.Canvas.Pen.Color := clRed;
      Bitmap.Canvas.Rectangle(20, 20, 60, 60);
  
      // Is this correct?
      Png.Assign(Bitmap);
      Png.SaveToFile('image.png');
    finally
      Png.Free();
      Bitmap.Free();
    end;
  end;
  </code></pre>