دانلود یک تصویر jpg و خروجی به صورت bmp
uses Jpeg, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP;
{ .... }
function DownloadJPGToBitmap(const URL : string; ABitmap: TBitmap): Boolean;
var
idHttp: TIdHTTP;
ImgStream: TMemoryStream;
JpgImage: TJPEGImage;
begin
Result := False;
ImgStream := TMemoryStream.Create;
try //delphi-center.blogfa.com
idHttp := TIdHTTP.Create(nil);
try
idHttp.Get(URL, ImgStream);
finally
idHttp.Free;
end;//delphi-center.blogfa.com
ImgStream.Position := 0;
JpgImage := TJPEGImage.Create;
try//delphi-center.blogfa.com
JpgImage.LoadFromStream(ImgStream);
ABitmap.Assign(JpgImage);
finally
Result := True;
JpgImage.Free;
end;
finally//delphi-center.blogfa.com
ImgStream.Free;
end;
end;
// Example:
procedure TForm1.Button1Click(Sender: TObject);
begin//delphi-center.blogfa.com
DownloadJPGToBitmap('http://www.sample.com/test.jpg', Image1.Picture.Bitmap);
end;
