Bueno, yo puedo quitarte algo de trabajo:
Código Delphi
[-]
uses WinInet, JPEG;
function DownloadToStream(Url: string; Stream: TStream): Boolean;
var
hNet: HINTERNET;
hUrl: HINTERNET;
Buffer: array[0..10240] of Char;
BytesRead: DWORD;
begin
Result := FALSE;
hNet := InternetOpen('agent', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
if (hNet <> nil) then
begin
hUrl := InternetOpenUrl(hNet, PChar(Url), nil, 0,
INTERNET_FLAG_RELOAD, 0);
if (hUrl <> nil) then
begin
while (InternetReadFile(hUrl, @Buffer, sizeof(Buffer), BytesRead)) do
begin
if (BytesRead = 0) then
begin
Result := TRUE;
break;
end;
Stream.WriteBuffer(Buffer,BytesRead);
end;
InternetCloseHandle(hUrl);
end;
InternetCloseHandle(hNet);
end;
end;
function DownloadToBmp(Url: string; Bitmap: TBitmap): Boolean;
var
Stream: TMemoryStream;
Jpg: TJPEGImage;
begin
Result:= FALSE;
Stream:= TMemoryStream.Create;
try
try
if DownloadToStream(Url, Stream) then
begin
Jpg:= TJPEGImage.Create;
try
Stream.Seek(0,soFromBeginning);
Jpg.LoadFromStream(Stream);
Bitmap.Assign(Jpg);
Result:= TRUE;
finally
Jpg.Free;
end;
end;
finally
Stream.Free;
end;
except end;
end;
La funcion DownloadToBmp se encarga de descargar una imagen jpeg de internet y la convierte automaticamente a Bmp. Una vez que tienes el bmp ya sabras tu lo que tienes que hacer con el.
Ejemplo de como usar la funcion:
Código Delphi
[-]
var
Bitmap: TBitmap;
begin
Bitmap:= TBitmap.Create;
try
if DownloadToBmp('http://www.clubdelphi.com/images/clubdelphi.jpg', Bitmap) then
begin
Bitmap.SaveToFile('c:\prueba.bmp');
end;
finally
Bitmap.Free;
end;
end;