我希望将网络上的图像转换为流(不保存)并将其显示在TImage上。 以下代码产生错误:
response := TMemoryStream.Create;
try
HttpGetBinary('http://www.example-url/example_image.jpg', response);
Image.Picture.LoadFromStream(response);
finally
response.Free;
end;
Project -------引发异常类'EReadError'并带有消息: 流读错误
这是Synapse库中的函数(在picture.inc中),错误指向:
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;
答案 0 :(得分: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;