Jump to content
MikeMon

Download Images from a URL

Recommended Posts

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

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
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
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;

 

  • Like 1

Share this post


Link to post
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 by KodeZwerg

Share this post


Link to post
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.

  • Like 1
  • Thanks 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×