How to get images from URL in Delphi

Greener picture Greener · Aug 4, 2009 · Viewed 22.4k times · Source

I am looking for any code samples that show how to pull images from URL into Delphi TImage component.

Thanks,

Answer

Mohammed Nasman picture Mohammed Nasman · Aug 4, 2009

With help of TMemoryStream and Indy component.

uses
  GIFImg;

procedure TForm1.btn1Click(Sender: TObject);
var
  MS : TMemoryStream;
  GIf: TGIFImage;
begin
  MS := TMemoryStream.Create;
  GIf := TGIFImage.Create;
  try
    IdHTTP1.get('http://www.google.com/intl/en_ALL/images/logo.gif',MS);
    Ms.Seek(0,soFromBeginning);       
    Gif.LoadFromStream(MS);
    img1.Picture.Assign(GIF);

  finally
    FreeAndNil(GIF);
    FreeAndNil(MS);
  end;
end;