此代码适用于 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
来替代它。PngComponents中Width/height
是只读的。
如何将32bpp BMP(例如从shell32.dll获取的)转换为PNG?
Assign
吗? - TLamaAssign
会生成黑色背景的PNG。 - Prog1020