利用TidHttp下载服务器图片

//从服务器上把图片下载到本地并处理
procedure TForm3.ImgShow(filename:string);
var
  imageStream:TMemoryStream;
  jpg:TJpegImage;
  imgFile:string;
  Bmp1,Bmp2 :TBitmap;
  w1,h1:Integer;
begin
  try
  //从网上将图片下传到本地,在下载时写入数据流
   imgFile:='http://192.168.X.X/Images/'+filename;
   imagestream := TMemoryStream.Create();
   jpg:=TJpegImage.Create;
   idhtp1.Get(imgFile,imagestream);
   imagestream.Position:=0;
   jpg.LoadFromStream(imagestream);
   //将图片缩放成900*450
   Bmp1 :=TBitmap.Create;
   Bmp2 :=TBitmap.Create;
   Bmp1.Assign (jpg);
   w1:=Bmp1.Width;
   h1:=Bmp1.Height;
   Bmp2.Width :=w1*900 div w1;
   Bmp2.Height :=h1*450 div h1;
   SetStretchBltMode(Bmp2.Canvas.Handle,HalfTone);
   StretchBlt(Bmp2.Canvas.Handle,0,0,900,450,
             Bmp1.Canvas.Handle,0,0,w1,h1,SRCCOPY);
   //保存图片
    jpg.Assign(bmp2);
    jpg.SaveToFile (strfilePath+'\'+filename);
    finally
      jpg.Free ;
      Bmp1.Free;
      Bmp2.Free;
    end;
end;

你可能感兴趣的:(procedure,图片下载,数据流,网上,下载服务器)