利用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;
本文出自 “畅想天空” 博客,请务必保留此出处http://kinwar.blog.51cto.com/3723399/1617594
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。