利用IDhttp实现图片下载

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdHTTP;

 

 


type
    TForm1 = class(TForm)
    Button1: TButton;
    IdHTTP1: TIdHTTP;
    procedure Button1Click(Sender: TObject);
  *******
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var s:TStringList;
    MStream:TMemoryStream;
    i:integer;

begin
  s:=TStringList.Create;
  s.Add('http://www.taomn.com/pic/bimg/albums/photos/1/0/1/101705/1139753842.jpg');
  s.Add('http://www.taomn.com/pic/bimg/albums/photos/1/0/1/101705/1139753793.jpg');
  s.Add('http://www.taomn.com/pic/bimg/albums/photos/1/0/1/101705/1139753782.jpg');
  for i:=0 to s.Count-1 do
    begin
      MStream:=TMemoryStream.Create;
      IdHttp1.Get(s[i],MStream);
      MStream.SaveToFile('c:\'+IntToStr(i)+'.jpg');
      MStream.Free;
    end;
  ShowMessage('下载完毕');
  s.Free;
end;
end.

IdHTTP的创建
{IdHTTP := TIdHTTP.Create(nil);
try
  IdHTTP.Get(URL, SavedStream);
finally
  IdHTTP.Free;
end;}

posted @ 2010-02-15 13:44  猪悟能  阅读(816)  评论(0编辑  收藏  举报