【问题标题】:How to create and return PNG with fpWeb?如何使用 fpWeb 创建和返回 PNG?
【发布时间】:2022-01-14 04:53:28
【问题描述】:

我想即时创建 PNG 图像并使用 fpWeb 包中的 HTTP-server 返回它。

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;

但应用程序在png.SetSize 线上崩溃,并出现错误External: SIGSEGV。我该如何解决这个问题?

我在 Windows 7(64 位)上使用最新的 Lazarus 2.0.12(32 位)。

【问题讨论】:

  • 我从不使用图形(更多用于表单显示),我通常使用 tlazintfimage 或 fpimage 图像类型,并且可能图形只是那些周围的外壳 试试看直接使用它们。

标签: http web png pascal lazarus


【解决方案1】:

我尝试了我从你的代码修改的这段代码。

procedure TForm1.Button1Click(Sender: TObject);
var
  png: Graphics.TPortableNetworkGraphic;
begin
  png := Graphics.TPortableNetworkGraphic.Create;

    png.SetSize(100, 100);
    png.Canvas.TextOut(10, 10, 'Hi artem!');
    png.SaveToFile('tst.png');
end; 

我保存了这张图片。

我认为关于 PNG 图像的代码没有问题。 我觉得可能是其他原因造成的。也许 DataModuleRequest 不允许有任何图形或 UI 加载处理或其他东西。不确定。

【讨论】:

    猜你喜欢
    • 2021-12-04
    • 1970-01-01
    • 2015-03-08
    • 1970-01-01
    • 2013-01-30
    • 2015-04-29
    • 2019-07-24
    • 1970-01-01
    • 2019-01-15
    相关资源
    最近更新 更多