Recent

Author Topic: Image component load photo from net  (Read 336 times)

alaa123456789

  • Sr. Member
  • ****
  • Posts: 260
  • Try your Best to learn & help others
    • youtube:
Image component load photo from net
« on: March 03, 2024, 02:03:23 pm »
Hello all

do Lazarus have image component load photo direct from net?
 thanks

wp

  • Hero Member
  • *****
  • Posts: 11917
Re: Image component load photo from net
« Reply #1 on: March 03, 2024, 02:20:42 pm »
No, AFAIK. Lazarus is a programming environment, and you must write at least a few lines of code to achieve this.

Code: Pascal  [Select][+][-]
  1. uses
  2.   fphttpclient, opensslsockets;
  3.  
  4. procedure LoadImageFromURL(URL: String; APicture: TPicture);
  5. var
  6.   stream: TMemoryStream;
  7.   http: TFPHttpClient;
  8. begin
  9.   stream := TMemoryStream.Create;
  10.   try
  11.     http := TFPHTTPClient.Create(nil);
  12.     try
  13.       http.Get(URL, stream);
  14.       stream.Position := 0;
  15.       APicture.LoadFromStream(stream);
  16.     finally
  17.       http.Free;
  18.     end;
  19.   finally
  20.     stream.Free;
  21.   end;
  22. end;
  23.  
  24. procedure TForm1.Button1Click(Sender: TObject);
  25. begin
  26.   LoadImageFromURL(Edit1.Text, Image1.Picture);
  27. end;    

alaa123456789

  • Sr. Member
  • ****
  • Posts: 260
  • Try your Best to learn & help others
    • youtube:
Re: Image component load photo from net
« Reply #2 on: March 03, 2024, 03:09:37 pm »


Code: Pascal  [Select][+][-]
  1. uses
  2.   fphttpclient, opensslsockets;
  3.  
  4. procedure LoadImageFromURL(URL: String; APicture: TPicture);
  5. var
  6.   stream: TMemoryStream;
  7.   http: TFPHttpClient;
  8. begin
  9.   stream := TMemoryStream.Create;
  10.   try
  11.     http := TFPHTTPClient.Create(nil);
  12.     try
  13.       http.Get(URL, stream);
  14.       stream.Position := 0;
  15.       APicture.LoadFromStream(stream);
  16.     finally
  17.       http.Free;
  18.     end;
  19.   finally
  20.     stream.Free;
  21.   end;
  22. end;
  23.  
  24. procedure TForm1.Button1Click(Sender: TObject);
  25. begin
  26.   LoadImageFromURL(Edit1.Text, Image1.Picture);
  27. end;    


Thanks WP

 

TinyPortal © 2005-2018