无法从网站更新图片框... [英] Can't get a picturebox to update from a website...

查看:119
本文介绍了无法从网站更新图片框...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,感谢您考虑提供帮助。我想要做的是使用webbrowser和webclient来显示/下载来自discogs的图像。以下是两个参考链接。即时通讯使用视觉工作室2017年。我是新的编程,并不能完全弄清楚为什么我一直得到503错误。非常感谢任何对这个问题的帮助...非常感谢所有在这里帮助我的人是我的来源样本...



...也很抱歉草率的格式= [





 Private Sub WebpageDocumentCompleted(ByVal sender As Object,ByVal e As WebBrowserDocumentCompletedEventArgs)
'选择webbrowser选项卡
WebBrowserTabControl.SelectedTab.Text = GetCurrentWebbrowser(WebBrowserTabControl).DocumentTitle

For Each Ele As HtmlElement In GetCurrentWebbrowser(WebBrowserTabControl).Document.Links
Dim eletarget As String = ele.GetAttribute(href)
'LINKS-ListBox.Items.Add(eletarget)'将链接添加到ListBox
下一个

对于每个ele As HtmlElement在GetCurrentWebbrowser(WebBrowserTabControl).Document.All
'浏览web文档并搜索jpg图像
如果ele.GetAttribute(src)。ToLower.Contains(。 jpg)T hen
Dim imgsrc As String = ele.GetAttribute(src)

'IMAGES-ListBox.Items.Add(imgsrc)'将所有.jpg图像添加到ListBox
尝试

Dim newlibraryimg作为New PictureBox
使用newlibraryimg
Dim tClient As WebClient = New WebClient
Dim tImage As Bitmap = Bitmap.FromStream(New MemoryStream(tClient.DownloadData) (imgsrc)))
Console.WriteLine(imgsrc)
.BackColor = Color.Yellow
.SizeMode = PictureBoxSizeMode.Zoom
.Size = New Size(132,76)' (130,74)
libraryholder.Controls.Add(newlibraryimg)
'AddHandler newlibraryimg.MouseHover,AddressOf curover
'AddHandler newlibraryimg.Click,AddressOf curclick
'AddHandler newlibraryimg.MouseLeave ,阿德雷ssOf curleave
。显示()
结束
Catch ex As Exception
MsgBox(ex.Message)
结束尝试
结束如果
下一个
结束子





资源主页: Amr Diab - Discogs中最好的Amr Diab(CD) [ ^ ]



图片页: Amr Diab的图片 - 最好的Amr Diab [ ^ ]



我的尝试:



我得到这个部分工作正常而不是与discogs = [我已经尝试了很多其他方法,但没有运气。 
我试过的东西......



私有子LoadImageFromWeb(byval spath As String,byval pic As Object)
Dim tClient As WebClient = New WebClient
Dim tImage As Bitmap = Bitmap.FromStream(New MemoryStream(tClient.DownloadData(spath)))
pic.Image = tImage
End Sub

解决方案

503是一个HTTP状态代码服务不可用

你有没有用你的代码?
是您尝试下载的网址是否正确?

它在你的浏览器中工作吗?





Picturebox可以自己加载图片,不需要aditional(不必要)webclient



 pic.Load(spath)
'
pic.LoadAsync(spath)



工作正常。


Hello all and thank you for considering to help. what i am trying to do is use a webbrowser and webclient to display/download the images from discogs. below are two link to reference. im using visual studios 2017. im new to programming and can't quite figure out why i keep getting a 503 error. any help with this issue is greatly appreciated... so thank you very much to all that assist me here is a sample of my source...

.... also sorry about the sloppy formatting =[


Private Sub WebpageDocumentCompleted(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)
    'selected webbrowser tab
    WebBrowserTabControl.SelectedTab.Text = GetCurrentWebbrowser(WebBrowserTabControl).DocumentTitle

    For Each ele As HtmlElement In GetCurrentWebbrowser(WebBrowserTabControl).Document.Links
        Dim eletarget As String = ele.GetAttribute("href")
        '    LINKS-ListBox.Items.Add(eletarget) 'Adds the Links to the ListBox
    Next

    For Each ele As HtmlElement In GetCurrentWebbrowser(WebBrowserTabControl).Document.All
        'go through the web document and search for jpg images
        If ele.GetAttribute("src").ToLower.Contains(".jpg") Then
            Dim imgsrc As String = ele.GetAttribute("src")

            '    IMAGES-ListBox.Items.Add(imgsrc) 'Adds all .jpg images to the ListBox
            Try

                Dim newlibraryimg As New PictureBox
                With newlibraryimg
                    Dim tClient As WebClient = New WebClient
                    Dim tImage As Bitmap = Bitmap.FromStream(New MemoryStream(tClient.DownloadData(imgsrc)))
                    Console.WriteLine(imgsrc)
                    .BackColor = Color.Yellow
                    .SizeMode = PictureBoxSizeMode.Zoom
                    .Size = New Size(132, 76) '(130, 74)
                    libraryholder.Controls.Add(newlibraryimg)
                    'AddHandler newlibraryimg.MouseHover, AddressOf curover
                    'AddHandler newlibraryimg.Click, AddressOf curclick
                    'AddHandler newlibraryimg.MouseLeave, AddressOf curleave
                    .Show()
                End With
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End If
    Next
End Sub



resource main page: Amr Diab - The Best Of Amr Diab (CD) at Discogs[^]

image page: Images for Amr Diab - The Best Of Amr Diab[^]

What I have tried:

i got this part working ok just not with discogs =[ i have tried many other ways but no luck.
things i have tried...


Private Sub LoadImageFromWeb(byval spath As String, byval pic As Object)
      Dim tClient As WebClient = New WebClient
      Dim tImage As Bitmap = Bitmap.FromStream(New MemoryStream(tClient.DownloadData(spath)))
      pic.Image = tImage
  End Sub

解决方案

503 is a HTTP Statuscode "Service Unavailable"
have you debuged your code?
is the URL you are trying to download correct?
is it working in your Browser?

and
Picturebox can load images itself, no ned for an aditional (unneccessary) webclient

pic.Load(spath)
'and 
pic.LoadAsync(spath)


work just fine.


这篇关于无法从网站更新图片框...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆