已知图片的URL地址,用代码怎样保存到磁盘

来源:百度知道 编辑:UC知道 时间:2024/05/09 20:12:12
已知图片的URL地址(如:http://image.baidu.com/i?ct=503316480&z=3&tn=baiduimagedetail&word=d&in=28523&cl=2&cm=1&sc=0&lm=-1&pn=15&rn=1&di=264528776&ln=2000)在ASP.ENT里怎样把图片下载到磁盘呢?(最好用VB代码,C#也行).
谢谢
还有没有其它方法呀?

我这是这么写的,应该很容易看懂吧

Private stream_Document As New ADODB.Stream

Public Sub SaveImageB(URL As String, SavePath As String)
Dim sFile
sFile = GetBody(URL) '取得图片的具休内容的过程
With stream_Document
.Type = 1 '以二进制模式打开
.Open
.write sFile '将字符串内容写入缓冲
.SaveToFile SavePath, 2 '将缓冲的内容写入文件
.Close
End With
End Sub

Private Function GetBody(URL)
' on error resume next
Dim Retrieval As New XMLHTTP30
'Set Retrieval = CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", URL, False, "", ""
.send
GetBody = .responseBody
End With
Set Retrieval = Nothing
End Function

vb里要先引用ADODB和XMLHTTP30,不懂可以问我

Private De