从网页浏览器获取图片到图片框

发布于 2024-09-28 13:24:24 字数 1230 浏览 0 评论 0原文

我在图片框中显示一些图片(多于一张)时遇到问题。

 <div id="salary_total" style="display: block;"><table style="border: 3px solid rgb(71, 5, 6); padding-right: 1px;" bgcolor="#ffffff" cellpadding="0" cellspacing="0"><tbody><tr><td><img src="./images/counter/b.gif"></td>
<td><img src="./images/counter/3.gif" border="0"></td>
<td><img src="./images/counter/3.gif" border="0"></td>
<td><img src="./images/counter/0.gif" border="0"></td>
<td><img src="./images/counter/8.gif" border="0"></td>
</tr></tbody></table> 

那些图片链接,显示为像 3308 这样的数字,并且每次页面加载时它都会改变。如何在图片框中显示这些图片(彼此相邻)。

Try
    Dim htmlDocument As HtmlDocument = Me.WebBrowser1.Document
    Dim htmlElementCollection As HtmlElementCollection = htmlDocument.Images
    For Each htmlElement As HtmlElement In htmlElementCollection
        Dim imgUrl As String = htmlElement.GetAttribute("src")
        If imgUrl.Contains("counter") Then
            Me.PictureBox1.ImageLocation = imgUrl.Substring(0, 41)
        End If
    Next

这个适用于第一张图片,我怎样才能再有 3 个图片框,并对其他 3 张图片做同样的事情?,就像 3.gif 将转到第一个图片框,依此类推?!

I am having a problem displaying some pictures (more than one) in a picturebox.

 <div id="salary_total" style="display: block;"><table style="border: 3px solid rgb(71, 5, 6); padding-right: 1px;" bgcolor="#ffffff" cellpadding="0" cellspacing="0"><tbody><tr><td><img src="./images/counter/b.gif"></td>
<td><img src="./images/counter/3.gif" border="0"></td>
<td><img src="./images/counter/3.gif" border="0"></td>
<td><img src="./images/counter/0.gif" border="0"></td>
<td><img src="./images/counter/8.gif" border="0"></td>
</tr></tbody></table> 

those picture links, shows like a number like 3308, and it changes every time the page loads. how can I display those pictures (next to each other) in a picturebox.

Try
    Dim htmlDocument As HtmlDocument = Me.WebBrowser1.Document
    Dim htmlElementCollection As HtmlElementCollection = htmlDocument.Images
    For Each htmlElement As HtmlElement In htmlElementCollection
        Dim imgUrl As String = htmlElement.GetAttribute("src")
        If imgUrl.Contains("counter") Then
            Me.PictureBox1.ImageLocation = imgUrl.Substring(0, 41)
        End If
    Next

This one works for the first picture, how can I have like 3 more pictureboxs, and do the same for the other 3 pictures?, like the 3.gif will go to the 1st picturebox, and so on?!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千纸鹤 2024-10-05 13:24:24

我想通了:这就是解决方案!谢谢

Try
            Dim htmlDocument As HtmlDocument = Me.WebBrowser1.Document
            Dim htmlElementCollection As HtmlElementCollection = htmlDocument.Images
            Dim ImagesFound As Integer = 0
            For Each htmlElement As HtmlElement In htmlElementCollection
                Dim imgUrl As String = htmlElement.GetAttribute("src")
                If imgUrl.Contains("counter") Then
                    ImagesFound+=1
                    Select Case ImagesFound
                         Case 1 
                              PictureBox1.ImageLocation = imgUrl
                              Label1.Text = PictureBox1.ImageLocation.ToString()
                         Case 2 
                              PictureBox2.ImageLocation = imgUrl
                              '... etc.
                    End Select

                End If
            Next
        Catch ex As Exception
        End Try

I figured it out: Here is the solution! Thanks

Try
            Dim htmlDocument As HtmlDocument = Me.WebBrowser1.Document
            Dim htmlElementCollection As HtmlElementCollection = htmlDocument.Images
            Dim ImagesFound As Integer = 0
            For Each htmlElement As HtmlElement In htmlElementCollection
                Dim imgUrl As String = htmlElement.GetAttribute("src")
                If imgUrl.Contains("counter") Then
                    ImagesFound+=1
                    Select Case ImagesFound
                         Case 1 
                              PictureBox1.ImageLocation = imgUrl
                              Label1.Text = PictureBox1.ImageLocation.ToString()
                         Case 2 
                              PictureBox2.ImageLocation = imgUrl
                              '... etc.
                    End Select

                End If
            Next
        Catch ex As Exception
        End Try
尤怨 2024-10-05 13:24:24

首先,您的 ImageLocation 将如下所示:

http://www.link.com./images/counter/8.gif

这可能不是您想要的。

其次,Shoban 说你应该使用常规文本和 CSS。他是对的。

第三,如果要在单个图片框中显示多个图像,则需要创建一个图像对象并将其他图像绘制到其中。有用于此目的的 VB.Net 函数以及本机 Windows API(CopyRect?)。

如果您愿意,可以使用多个图片框。

First, you ImageLocation will come out like this:

http://www.link.com./images/counter/8.gif

That's probably not what you intended.

Second, Shoban said that you should be using regular text and CSS. He's right.

Third, If you want to display multiple images in a single picturebox, you will need to make a single image object and draw the other images into it. There are VB.Net functions for that and also native Windows API (CopyRect?).

You can use multiple picture boxes if you like.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文