【问题标题】:vb.net image download and populate on the picturebox errorvb.net 图像下载并填充图片框错误
【发布时间】:2015-11-01 01:39:03
【问题描述】:

我想从网上下载图片文件,并在表格上的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

【问题讨论】:

  • 非常抱歉,我更改了标签

标签: c# vb.net


【解决方案1】:

我没有足够的 cmets 代表,所以我会在这里写

尝试在client.DownloadFileAsync(myUrl, "cap.png")之后添加一行client.Dispose()

【讨论】:

    【解决方案2】:

    使用 DownloadFile 而不是 DownloadFileAsync。或者,如果您不需要文件,则可以使用以下内容:

        static Image DownloadImage(string address)
        {
            using (var client = new WebClient())
                return Image.FromStream(new MemoryStream(client.DownloadData(address)));
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-16
      • 2023-04-05
      • 2014-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多