TPortableNetworkGraphic.CreateIntfImage doesn't create an image that supports alpha. It also loads the PNG into the image, which isn't required if you are creating a new image.
Also, you dont need TPortableNetworkGraphic, since TLazIntfImage will load/save png/jpeg/etc.
So, try this:
procedure TForm1.Button1Click(Sender: TObject);
var
X, Y: integer;
LColor: TFPColor;
LImage: TLazIntfImage;
begin
LImage := TLazIntfImage.Create(0, 0, [riqfRGB, riqfAlpha]);
try
LImage.SetSize(32, 32);
for X := 0 to LImage.Width - 1 do begin
for Y := 0 to LImage.Height - 1 do begin
LColor.red := (128 + X) shl 8;
LColor.green := (128 + Y) shl 8;
LColor.blue := 128 shl 8;
LColor.alpha := 200 shl 8; // no matter what value here, always get full opacity
LImage.Colors[X, Y] := LColor;
end;
end;
LImage.SaveToFile('test.png');
finally
LImage.Free;
end;
end;
NOTE: There does seem to be a bug in TLazIntfImage which I've know about for a while. You cant provide a width/height via the constructor.
Hence the additional SetSize() command.