Du musst beachten, dass AlphaScanline ein Byte, Scanline aber ein TRGBQuad (bzw. je nach PixelFormat) liefert.
Mit meinem Avatar erfolgreich getestet:
Delphi-Quellcode:
TCardinalArray = Array[0..0] of Cardinal;
PCardinalArray = ^TCardinalArray;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
Png: TPNGObject;
x, y: Integer;
pTo: PCardinalArray;
pFrom: PByteArray;
Alpha: Byte;
begin
if OpenPictureDialog1.Execute then
begin
Png := TPNGObject.Create;
try
Png.LoadFromFile(OpenPictureDialog1.FileName);
Image1.Width := Png.Width * 2;
Image1.Height := Png.Height;
Image1.Picture.Bitmap.Width := Png.Width * 2;
Image1.Picture.Bitmap.Height := Png.Height;
Image1.Picture.Bitmap.PixelFormat := pf32bit;
Image1.Canvas.Draw(0, 0, Png);
for y := 0 to Png.Height - 1 do
begin
pFrom := Png.AlphaScanline[y];
pTo := Image1.Picture.Bitmap.ScanLine[y];
for x := 0 to Png.Width - 1 do
begin
Alpha := pFrom[x];
pTo[x + Png.Width] := Alpha or Alpha shl 8 or Alpha shl 16;
end;
end;
finally
Png.Free;
end;
end;
end;