【问题标题】:Why the transparency of a PNG image is lost when I use TPicture?为什么使用 TPicture 时 PNG 图像的透明度会丢失?
【发布时间】:2013-09-13 12:14:03
【问题描述】:

我正在使用此代码将透明 png 转换为 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但透明度丢失,我缺少什么?

【问题讨论】:

  • @TLama 至少我学到了一些东西...谢谢!

标签: delphi bitmap png delphi-xe2


【解决方案1】:

尝试使用Assign 方法。这将保持透明度。

像这样。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-19
    • 2013-02-16
    • 1970-01-01
    • 1970-01-01
    • 2016-01-22
    • 2017-12-27
    • 2012-11-20
    • 1970-01-01
    相关资源
    最近更新 更多