jeudi 9 décembre 2021

How to create and return PNG with fpWeb?

I want to create PNG image on the fly and return it using HTTP-server from fpWeb package.

procedure TFPWebModule1.DataModuleRequest(Sender: TObject; ARequest: TRequest;
  AResponse: TResponse; var Handled: Boolean);
var
  png: Graphics.TPortableNetworkGraphic;
begin
  png := Graphics.TPortableNetworkGraphic.Create;
  try
    png.SetSize(100, 100);
    png.Canvas.TextOut(10, 10, 'Hello world!');

    AResponse.ContentType:='image/png';
    AResponse.ContentStream := TMemoryStream.Create;
    png.SaveToStream(AResponse.ContentStream);
    AResponse.ContentLength := AResponse.ContentStream.Size;
    AResponse.SendContent;
    AResponse.ContentStream := nil;
  finally
    png.Free;
  end;

  Handled:=true;
end;

But application crashes on the line png.SetSize with error External: SIGSEGV. How can I fix this?

I use latest Lazarus 2.0.12 (32bit) on Windows 7 (64bit).




Aucun commentaire:

Enregistrer un commentaire