1

I'm using this code to convert a transparent png to a 32 bpp bmp.

var
   Picture : TPicture;
   BMP : TBitmap;    
begin
  Picture := TPicture.Create;
  try
    Picture.LoadFromFile('Foo.png');
     BMP := TBitmap.Create;
     try
       BMP.PixelFormat:=pf32bit;
       BMP.Width := Picture.Width;
       BMP.Height := Picture.Height;
       BMP.Canvas.Draw(0, 0, Picture.Graphic);
       BMP.SaveToFile('Foo.bmp');
       finally
         BMP.Free;
       end;
     finally
       Picture.Free;
      end;
end;

The image is converted to bmp but the transparency is lost, what I'm missing?

1
  • 1
    @TLama At least I learned something... Thanks!
    – ppeterka
    Sep 9, 2013 at 22:49

1 Answer 1

4

Try using the Assign method. this will preserve the transparency.

like so.

 BMP := TBitmap.Create;
 try
   BMP.Assign(Picture.Graphic);
   BMP.SaveToFile('Foo.bmp');
 finally
     BMP.Free;
 end;
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.