MikeMon 12 Posted April 8, 2021 Currently I use TTMSFNCImage to download images from a URL; using the LoadFromURL procedure. I'm looking for alternatives to do the same, to try and see which way is faster and more efficient. Any ideas? Share this post Link to post
Vandrovnik 215 Posted April 8, 2021 THTTPClient? http://docwiki.embarcadero.com/Libraries/Sydney/en/System.Net.HttpClient.THTTPClient Share this post Link to post
KodeZwerg 54 Posted April 8, 2021 for windows i would use winapi, like that oneliner: Result := URLMon.URLDownloadToFile(nil, PChar('http://www.somewhere.com/something.gif'), PChar('a:\local\file.ext'), 0, nil) = 0; Share this post Link to post
MikeMon 12 Posted April 9, 2021 9 hours ago, Vandrovnik said: THTTPClient? http://docwiki.embarcadero.com/Libraries/Sydney/en/System.Net.HttpClient.THTTPClient Hi. Do you have a working example for reference? Share this post Link to post
MikeMon 12 Posted April 9, 2021 8 hours ago, KodeZwerg said: for windows i would use winapi, like that oneliner: Result := URLMon.URLDownloadToFile(nil, PChar('http://www.somewhere.com/something.gif'), PChar('a:\local\file.ext'), 0, nil) = 0; Hi. I'm using it for multi-device apps. Share this post Link to post
Vandrovnik 215 Posted April 9, 2021 53 minutes ago, MikeMon said: Hi. Do you have a working example for reference? uses System.Net.HttpClient; procedure TMainForm.Button1Click(Sender: TObject); var HttpClient: tHttpClient; m: tMemoryStream; begin m:=tMemoryStream.Create; try HttpClient:=tHttpClient.Create; try HttpClient.Get('https://www.embarcadero.com/images/logos/logo-black-corp-grey.png', m); finally FreeAndNil(HttpClient); end; m.SaveToFile('r:\img.png'); finally FreeAndNil(m); end; end; 1 Share this post Link to post
KodeZwerg 54 Posted April 9, 2021 (edited) 2 hours ago, MikeMon said: Hi. I'm using it for multi-device apps. {$IFDEF MSWindows} // code that run when windows is used {$ENDIF MSWindows} i really thought that was your question, find out other methods. Edited April 9, 2021 by KodeZwerg Share this post Link to post
David Schwartz 430 Posted April 13, 2021 On 4/8/2021 at 2:02 PM, MikeMon said: Currently I use TTMSFNCImage to download images from a URL; using the LoadFromURL procedure. I'm looking for alternatives to do the same, to try and see which way is faster and more efficient. Any ideas? The FNC components are intended to save you the most EXPENSIVE time -- YOUR PROGRAMMING TIME. If you don't value your time, then don't bother using them. You could also look at the source code and see what they're calling "under the hood" to investigate if there may be a more efficient approach on one platform or another. There may well be. But so what? In order to get a set of components that work and act the same on all platforms, they've needed to implement certain abstractions that are necessarily going to have a cost. That said, the time of the data transfers in this instance will, in most cases, swamp out the abstraction logic, unless they're doing unnecessary data copies. The truth is, most people do not bother to optimize their images in the first place. So you're looking in the wrong place for large speed improvements! Do you have any idea how much bandwidth is wasted by people who take 16 MPixel images then send them to their friends to look at in a 1" x 1" box on their cell phone? A 16 MP image is like a full HD screen in resolution; the 1" x 1" box on the cell phone is under 10kb for an image that most people couldn't see any difference between the two. You need to optimize the images BEFORE they're downloaded to get the most sigificant improvement in DL speeds! Because there's nothing you can do to move an 8MB image as if it's only 10KB in size. 1 1 Share this post Link to post