[英]vb.net image download and populate on the picturebox error
我想從互聯網上下載圖像文件,然后將此圖像文件打開到窗體上的picturebox1中。
我將下載的圖片圖像名稱更改為cap.png
然后我將此文件打開到picturebox1上,但是這里有問題。
總是出現錯誤,例如“文件被其他進程使用”或“內存不足”
我整天試圖使它工作,但我不知道
如果有人幫助我非常感謝
Dim client As New WebClient
remBadstring = captchaMatch.Value.Replace("""", "")
Dim myUrl = New Uri(remBadstring)
client.DownloadFileAsync(myUrl, "cap.png")
'My.Computer.Network.DownloadFile(myUrl, Application.StartupPath & "/cap.png")
Dim img As Image
Dim tmp As Image = Image.FromFile("cap.png")
img = New Bitmap(tmp)
tmp.Dispose()
PictureBox1.Load(remBadstring) ' error hapen.
'PictureBox1.Image = Image.FromFile("cap.png")
Application.DoEvents()
Dim myUrl2 As String = remBadstring
我沒有足夠的代表發表評論,所以我在這里寫
嘗試在client.DownloadFileAsync(myUrl, "cap.png")
添加。再添加一行client.Dispose()
使用DownloadFile而不是DownloadFileAsync。 或者,如果不需要文件,則可以使用以下命令:
static Image DownloadImage(string address)
{
using (var client = new WebClient())
return Image.FromStream(new MemoryStream(client.DownloadData(address)));
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.