unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
  StdCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    Image1: TImage;
    OpenDialog1: TOpenDialog;
    procedure Button1Click(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

uses
  psdtest;

{$R *.lfm}

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
var
  Buf: Pointer;
  Len, Errno: integer;
  MS: TMemoryStream;
begin
  if not OpenDialog1.Execute then
    Exit;
  PSD2PNG(PChar(OpenDialog1.FileName), @Buf, @Len, @Errno);
  if Errno <> 0 then
    Exit;
  try
    MS := TMemoryStream.Create;
    try
      MS.WriteBuffer(Buf^, Len);
      MS.Position := 0;
      Image1.Picture.LoadFromStream(MS);
    finally
      MS.Free;
    end;
  finally
    Cfree(Buf);
  end;
end;

end.
