function TReportRunTime.GetImageFromUrl(var Bmp:TBitmap;url:String):boolean;
var
picture : Tpicture;
jpg:TJpegImage;
imagestream:TMemoryStream;
IdHTTP1:TIdHTTP;
begin
Result := False;
imagestream := TMemoryStream.Create();
jpg:=TJpegImage.Create;
picture := Tpicture.Create;
IdHTTP1 := TIdHTTP.create(nil);
try
try
//IdHTTP1.IOHandler := IdSSLIOHandlerSocketOpenSSL1;
IdHTTP1.HandleRedirects := False; //允许头转向
IdHTTP1.ReadTimeout := 10000; //请求超时设置
IdHTTP1.HandleRedirects := False; //支持重定向
IdHTTP1.Request.CacheControl := ‘no-cache’; //不缓存
IdHTTP1.Request.AcceptEncoding := ‘’; // ‘gzip, deflatee’; 压缩格式,如果不需要,就置空
IdHTTP1.HTTPOptions := IdHTTP1.HTTPOptions + [hoKeepOrigProtocol]; //设置协议
IdHTTP1.ProtocolVersion := pv1_1;
IdHTTP1.Request.Connection := ‘Keep-Alive’;
//IdHTTP1.Request.ContentType := ‘application/json’; //设置内容类型为json
{IdHTTP1.ReadTimeout := 10000;
IdHTTP1.ProtocolVersion := pv1_1;}
IdHTTP1.Get(url,imagestream);
imagestream.position := 0;
jpg.LoadFromStream(imagestream);
picture.Assign(jpg);
// if (Bmp = nil) then
//begin
//end;
Bmp := TBitmap.Create;
Bmp.Assign(picture.Graphic);
//Bmp.SaveToFile(‘d:\’+ Copy(url, LastPos(‘/‘,url)+1,LastPos(‘?’,url)-LastPos(‘/‘,url)-1));
Result := True;
except
end;
finally
picture.Free;
jpg.Free;
IdHTTP1.Free;
imagestream.Free;
end
end;