How to load a picture from the Internet? lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- Vlad1997 · 2010-01-07 18:36 How to load a picture from the Internet? Formats: BMP, JPEG and GIF. OS: Ubuntu ---------------------------------------------------------------------- skalogryz · 2010-01-07 19:30 Please, review examples and documentation of the following component: http://wiki.freepascal.org/lNet ---------------------------------------------------------------------- Vlad1997 · 2010-01-08 11:25 And how to use it? ---------------------------------------------------------------------- skalogryz · 2010-01-08 13:53 have you tried any of lnet examples? http://svn.freepascal.org/svn/fpcprojects/lnet/trunk/examples/visual/ ---------------------------------------------------------------------- Vlad1997 · 2010-01-08 16:27 Thank you And how to load just picture? Code: [Select]function TMainForm.HTTPClientInput(ASocket: TLHTTPClientSocket; ABuffer: pchar;   ASize: dword): dword; var   oldLength: dword; begin   oldLength := Length(HTTPBuffer);   setlength(HTTPBuffer,oldLength + ASize);   move(ABuffer^,HTTPBuffer[oldLength + 1], ASize);   MemoHTML.Text := HTTPBuffer;   MemoHTML.SelStart := Length(HTTPBuffer);   AppendToMemo(MemoStatus, IntToStr(ASize) + '...');   Result := aSize; // tell the http buffer we read it all end; ---------------------------------------------------------------------- theo · 2010-01-08 16:35 Probably easier with Synapse's HttpGetBinary http://synapse.ararat.cz/doc/help/httpsend.html#HttpGetBinary ---------------------------------------------------------------------- skalogryz · 2010-01-08 19:22 Quote from: Vlad1997 on January 08, 2010, 05:27:18 pmThank you And how to load just picture? Provide Lnet component with URL of "just picture", let's say: http://www.mysite.com/image.png if you don't know the exact address, you'll need to load an .html file and parse it... (that's how browsers work) After you're sure that lnet is loading the picture (not .html), you can decide what to do with the data. The Lnet component writes the data from ABuffer to a stream... let's say TMemoryStream or TFileStream (if you need to store the picture into a file). If you need to show the picture on the screen you can later load and show it, using Graphics unit. Code: [Select]uses   ...lnet, graphics... var   pngstream: TStream;   pngimage : TPortableNetworkGraphics; function TMainForm.HTTPClientInput(ASocket: TLHTTPClientSocket; ABuffer: pchar;   ASize: dword): dword; begin   pngstream.Write(ABuffer^, ASize); end; procedure TMainForm.ShowPicture; begin   if not Assigned(png) then begin     pngimage:=TPortableNetworkGraphics.Create;     pngstream.Position:=0;     pngimage.LoadFromStream(pngstream);   end;   Invalidate; end; procedure TMainForm.FormPaint; begin   if Assigned(pngimage) then     Canvas.Draw(0,0,pngimage); end; It all depends on what you mean saying "how to load a picture". Lnet will help you to get the picture data, but it's up to you how to use it. P.S. don't ask for the examples, write your own