PngComponents:将32bpp bmp转换为png

3
此代码适用于 G.Daud 的 PngImage 组件。现在,在D7中将PngImage替换为PngComponents后,它无法编译。(http://code.google.com/p/cubicexplorer/downloads/list
function Bmp32ToPng(bmp: TBitmap): TPngObject;
var
  x, y: integer;
  src, dst: PngImage.pByteArray;
begin
  Result:= nil;
  if bmp.PixelFormat<>pf32bit then
    Exit;

  Result:= TPngObject.CreateBlank(COLOR_RGBALPHA, 8, bmp.Width, bmp.Height);
  Result.Canvas.Draw(0, 0, bmp);
  for y:= 0 to bmp.Height-1 do begin
    src:= bmp.ScanLine[y];
    dst:= Result.AlphaScanLine[y];
    for x:= 0 to bmp.Width-1 do
      dst[x]:= src[x*4+3];
  end;
end;
Createblank方法在PngComponents中不存在。无法用简单的Create然后设置Width/height来替代它。PngComponentsWidth/height是只读的。

如何将32bpp BMP(例如从shell32.dll获取的)转换为PNG?


1
你尝试过使用 Assign 吗? - TLama
2
你可能使用了不同版本的PngImage.pas,它是与PngComponents一起提供的。实际上,D2009+随附的PngImage版本具有CreateBlank构造函数。 - Uwe Raabe
@Uwe,是的,我使用CubicExplorer的D7版本。有没有办法编写Bmp32ToPng过程?它必须接受bmp(例如从shell32.dll中提取的TBitmap)并写入32bpp png。 - Prog1020
@TLama,Assign会生成黑色背景的PNG。 - Prog1020
4
请删除、重命名或移动PngComponents附带的pngimage.pas和pnglang.pas文件。 - Uwe Raabe
1个回答

1

GraphicEx和PngComponents以及pngimage之间存在冲突。解决方法如下:

1)将它们始终按特定顺序放置在uses子句中-首先是GraphicEx或PngComponents,最后是pngimage。

2)构建项目。修改uses子句后仅运行(或编译)项目是不够的。

PS)pngimage与PNG组件包一起安装,但此版本已过时。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接