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

Asked

Viewed 2,508 times

1

I’m trying to open an image that’s on a site of mine, I can’t use Twebbeowser because it has a vertical scrollbar that I can’t remove, so I only have Timage.

  • Get a look at this link: https://stackoverflow.com/questions/1227646/how-to-get-images-from-url-in-delphi

1 answer

2


You can use the Idhttp component for this. Create a new project, play an Idhttp component and another Idantifreeze in the form, also a Timage and a Tbutton. Then add the following code to the Button 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 too heavy, I recommend to throw this procedure inside a thread.

I hope I’ve helped!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.