1

我想将网络上的图像导入流(不保存)并将其显示在 TImage 上。以下代码会产生错误:

response := TMemoryStream.Create;
try
   HttpGetBinary('http://www.example-url/example_image.jpg', response);
   Image.Picture.LoadFromStream(response);
finally
   response.Free;
end;

项目 ------- 引发异常类 'EReadError' 并带有消息:流读取错误

这是错误指向的 Synapse 库(在图片中)中的函数:

function TPicFileFormatsList.FindByStreamFormat(Stream: TStream): TGraphicClass;
var
  I: Integer;
begin
  for I := Count - 1 downto 0 do
  begin
    Result := GetFormats(I)^.GraphicClass;
    if Result.IsStreamFormatSupported(Stream) then   // <<<<<< this is the error line
      Exit;
  end;
  Result := nil;
end;
4

1 回答 1

1

您必须JPEGLib在项目中的某处包含该单元,以便注册 JPEG 图形类。

uses
  JPEGLib, // to support JPEG
  PNGcomn, // to support PNG
  httpsend;

response := TMemoryStream.Create;
try
   if HttpGetBinary('http://www.example-url/example_image.jpg', response) then
   begin
     response.Seek( 0, soFromBeginning );
     Image.Picture.LoadFromStream( response );
   end;
finally
   response.Free;
end;
于 2014-02-19T10:41:15.787 回答