3
votes

This code works on the PngImage component (from G.Daud). Now it doesn't compile after PngImage is replaced with PngComponents for D7 (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;

The Createblank method does not exist in PngComponents. It can't be replaced with a simple Create then setting Width/height. Width/height are R/O in PngComponents.

How to convert 32bpp BMP (e.g. got from shell32.dll) to PNG?

1
Have you tried Assign ?TLama
You are probably using different versions of PngImage.pas which comes with PngComponents. The PngImage version coming with D2009+ actually has a CreateBlank constuctor.Uwe Raabe
@Uwe, yes i use D7 version from CubicExplorer. Any way to write Bmp32ToPng procedure needed. It must take bmp (TBitmap extracted from shell32.dll e.g.) and write 32bpp pngProg1020
@TLama, Assign gives Black BG png.Prog1020
Delete, rename or move away the files pngimage.pas and pnglang.pas that came with PngComponents.Uwe Raabe

1 Answers

1
votes

GraphicEx and PngComponents and pngimage are conflicting. To solve it:

1) always put them in uses clause in specific order - first - GraphicEx or PngComponents, last - pngimage.

2) build Project. It is not enough to run (or compile) project after uses clause was changed.

PS) pngimage installed with PNGcomponent package, BUT this version is outdated