You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Graphics32 2.0正式版中GR32_PNG位置及PNG透明加载问题

Delphi 12下Graphics32 2.0加载带透明PNG的解决方案

在Graphics32 2.0版本中,原有的GR32_PNG、GR32_PortableNetworkGraphic单元已被移除,转而依赖VCL原生的PNG处理组件。要保留透明效果加载资源中的PNG到TImage32,可以通过VCL的TPngImage中转实现:

实现代码

uses
  GR32, GR32_Image, Vcl.Imaging.pngimage;

var
  LogoStream: TResourceStream;
  PngImage: TPngImage;
begin
  LogoStream := TResourceStream.Create(MainInstance, 'MyLogo', RT_RCDATA);
  try
    PngImage := TPngImage.Create;
    try
      PngImage.LoadFromStream(LogoStream);
      // 将PNG图像(含透明通道)赋值给Bitmap32
      Image32Logo.Bitmap.Assign(PngImage);
    finally
      PngImage.Free;
    end;
  finally
    LogoStream.Free;
  end;
end;

说明

  • 引入Vcl.Imaging.pngimage单元是为了使用TPngImage,它能正确解析PNG的alpha透明通道。
  • 直接调用Bitmap32.LoadFromStream会使用VCL的TBitmap加载逻辑,无法正确保留PNG的透明信息,因此需要通过TPngImage中转后再赋值给Bitmap32。
  • 确保资源中的PNG文件本身包含有效的透明通道(alpha通道或索引透明),TPngImage会自动识别并传递给Bitmap32。

内容的提问来源于stack exchange,提问作者AlexV

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 21:13:17