Load a png image from the web (delphi fmx)

  

I would like to load png images from the web, but with the code below not all images do get correctly into the stream (while posting the url in a webbrowser, e.g. edge, does give the image correctly). For example, the first url in the code gives a loading bitmap failed error (in the stream FSize is only 14?), while the second url does not give a problem. Does anyone know how to download the first url correctly?
For this piece of code to work, a TButton and a TImage was put on a form.
System.Net.HttpClientComponent was added in the uses. I am using Delphi 10.3.3. fmx.
Thanks,
Gerard
procedure TForm1.Button1Click(Sender: TObject);
var ms: TmemoryStream;
httpCli: TNetHTTPClient;
url: string;
begin
httpCli := TNetHTTPClient.Create(nil);
ms := TMemoryStream.Create();

url := ‘https://a.tile.openstreetmap.org/11/1050/674.png’;
// url := ‘https://upload.wikimedia.org/wikipedia/commons/d/d5/Japan_small_icon.png’;

httpCli.Get(url,ms);
ms.Position := 0;
Image1.Bitmap.LoadFromStream(ms);

ms.free;
httpCli.free;
end;

Comments are closed.