How to open a WEB image on a Timage in Delphi?

1

I'm trying to open an image that is on my site, I can not use TWebBeowser because it has a vertical ScrollBar that can not be removed, so I only have Timage left.

    
asked by anonymous 01.09.2015 / 04:14

1 answer

2

You can use the IdHTTP component for this. Create a new project, throw an IdHTTP component and another IdAntiFreeze in the form, also a TImage and a TButton. Then add the following code in the Button's OnClick event:

var
  Jpeg: TJpegImage;
  Strm: TMemoryStream;
begin
  Screen.Cursor := crHourGlass;
  Jpeg := TJpegImage.Create;
  Strm := TMemoryStream.Create;
  try
    IdHttp.Get('http://www.site.com.br/imagem.jpg', Strm);
    if (Strm.Size > 0) then
    begin
      Strm.Position := 0;
      Jpeg.LoadFromStream(Strm);
      Image1.Picture.Assign(Jpeg);
    end;
  finally
    Strm.Free;
    Jpeg.Free;
    Screen.Cursor := crDefault;
  end;

If the image is very heavy, I recommend that you play this procedure inside a thread.

I hope I have helped!

    
03.09.2015 / 18:35