为什么一个PNG图像的透明度,当我使用TPicture丢失? [英] Why the transparency of a PNG image is lost when I use TPicture?

查看:504
本文介绍了为什么一个PNG图像的透明度,当我使用TPicture丢失?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这个code到一个透明的PNG转换为32 BPP BMP。

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;

图片转换为bmp,但失去透明性,我错过了什么?

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

推荐答案

尝试使用分配方法。这将preserve透明度。

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

像这样

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

这篇关于为什么一个PNG图像的透明度,当我使用TPicture丢失?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆