Question Web browser images

aliusman

Member
Joined
Jul 5, 2011
Messages
9
Programming Experience
Beginner
hi

i am creating a web browser using microsoft vb.net 2008 and i want to save all images only displaying on any web page in my browser. i have added check box to save images.
browser.PNG
when i click on check box , the browser will prompt to save only images files on web page.
 
Private Function GetImageUrls() As String()
If (WebBrowser1.Document IsNot Nothing) Then
Dim
Urls(WebBrowser1.Document.Images.Count) As String

For
Each ImgElement As HtmlElement In WebBrowser1.Document.Images
Urls(Urls.Length) = ImgElement.GetAttribute("SRC")
Next
GetImageUrls = Urls

Else

Dim
Urls(0) As String
GetImageUrls = Urls

End
If

End Function

It still not working. Giving Error "URI Formats Not Supported".
 
I think that exception message relates to attempting to use "http://" as destination name when downloading.
 
i have solved the problem

' Made By Ali Usman

Private Function GetImageUrls() As String()
Dim filenamestr As String
Dim path As String
Dim cnt As Integer
cnt = 0

FBD1.RootFolder = Environment.SpecialFolder.Desktop
FBD1.ShowNewFolderButton = True

If FBD1.ShowDialog = Windows.Forms.DialogResult.OK Then
path = FBD1.SelectedPath
Else
path = FBD1.RootFolder = Environment.SpecialFolder.Desktop

End If


If (WebBrowser1.Document IsNot Nothing) Then
Dim Urls(WebBrowser1.Document.Images.Count) As String

For Each ImgElement As HtmlElement In WebBrowser1.Document.Images

filenamestr = filename_extractor(ImgElement.GetAttribute("SRC"))

Urls(cnt) = ImgElement.GetAttribute("SRC")
PictureBox1.Load(Urls(cnt))

PictureBox1.Image.Save(path & "\" & filenamestr)
System.Windows.Forms.Application.DoEvents()
cnt = cnt + 1
Next

GetImageUrls = Urls

Else
Dim Urls(0) As String
GetImageUrls = Urls
MsgBox("Images Saved")
End If
End Function

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
GetImageUrls()
End If
End Sub

Private Function filename_extractor(ByVal filename As String)

Dim str As String
Dim str2 As String
Dim n As Integer
str2 = ""
str = filename

For n = 0 To str.Length - 1
If (Microsoft.VisualBasic.Mid(str, str.Length - n, 1) = "/") Then
filename_extractor = str2
Exit Function
End If

str2 = Microsoft.VisualBasic.Mid(str, str.Length - n, 1) & str2

Next n

filename_extractor = str2

End Function

End Class
 
The most significant part of that time relates to downloading the images again from the internet, I posted a link to a method that can be used to get the images from the computers local cache instead. If that was not an option you would normally use a secondary thread to do the time consuming work off of the UI thread.
 
Back
Top