unit Unit1;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.ExtDlgs,
Vcl.ExtCtrls, PNGImage;
type
TForm1 = class(TForm)
Image1: TImage;
PaintBox1: TPaintBox;
procedure FormClick(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure CopyAlphaChannel(SrcImage: TPngImage; DstBitmap: TBitmap);
var x, y: Integer;
AlphaSrcLine, SrcLine:
VCL.Imaging.PngImage.pByteArray;
DstLine: PByteArray;
begin
if (SrcImage.Width<>DstBitmap.Width) or (SrcImage.Height<>DstBitmap.Height) then
Exit;
DstBitmap.PixelFormat:=pf32Bit;
for y:=0 to SrcImage.Height-1 do
begin
AlphaSrcLine:=SrcImage.AlphaScanline[y];
SrcLine:=SrcImage.Scanline[y];
DstLine:=DstBitmap.Scanline[y];
for x:=0 to SrcImage.Width-1 do
begin
DstLine^[4*x+0]:=SrcLine^[3*x+0];
DstLine^[4*x+1]:=SrcLine^[3*x+1];
DstLine^[4*x+2]:=SrcLine^[3*x+2];
DstLine^[4*x+3]:=AlphaSrcLine^[x];
end;
end;
DstBitmap.AlphaFormat:=afDefined;
end;
//
function Png32ToBmp32(PNGGraphic: TGraphic): TBitmap;
var png: TPNGImage;
begin
png:=TPNGImage.Create;
png.Assign(PNGGraphic);
result:=TBitmap.Create;
result.SetSize(png.Width, png.Height);
CopyAlphaChannel(png, result);
png.Free;
end;
//
procedure TForm1.FormClick(Sender: TObject);
var bmp: TBitmap;
begin
bmp:=Png32ToBmp32(Image1.Picture.Graphic);
PaintBox1.Canvas.Draw(0, 0, bmp);
bmp.Free;
end;
end.