[RESOLVED] Grabbing Images With Webbrowser
Hi,
My prog takes a location the user inputs and searches for a map of that location through a webbrowser. I need to be able to take the image from the webbrowser and show it in a picturebox on my form. The name of the picture will always remain constant but the location is always different. The page where I submit the location the user input is sent is here . Type in 'Sandton' into that first textbox and the map which comes up is the image which I would like to get with my webbrowser into a picturebox.
Thanx a lot,
Re: Grabbing Images With Webbrowser
Take a look at my code examples throughout this thread.
http://www.vbforums.com/showthread.php?t=330341
Re: Grabbing Images With Webbrowser
I already looked at that RobDog888, but I couldnt find out how to take the images with a webbrowser and move them to a Picturebox.
I expect it will be using the MS HTML Object Library, and then something like
VB Code:
Dim objhtml as new MSHTML.MSHTMLDocument
Picturebox.Picture = LoadPicture(objhtml.Images(0))
But that exact code doesnt work, so please explain to me how to do it.
Thanx,
Re: Grabbing Images With Webbrowser
I think you would have to use the Inet control then to download the page and parse out the "<img" or "src=" tags. Then use the Open filename to put the binary picture in a local file and load to a picturebox. This is how I did it before.
VB Code:
Dim b() As Byte
Dim sSrc As String
Inet1.URL = "http://www.somepage.com"
txtImage = Inet1.OpenURL("http://www.somepage.com", icString)
'Parse the page in txtImage for the src= and place in a var
'
'sSrc = parsed path
'
b() = Inet1.OpenURL(sSrc, icByteArray)
Open "C:\MyImage.gif" For Binary As #1
Put #1, , b()
Close #1
imgPicture.Picture = LoadPicture("C:\MyImage.gif")
Re: Grabbing Images With Webbrowser
hmm... What is icString, and what is meant to be in sSrc?
Did you take a look at the link of the image I need to capture?
Thanx,
Re: Grabbing Images With Webbrowser
That code will download the html as a string (icString)
You will have to parse the filename from the data that is returned, and then download that file (sSrc)
Re: Grabbing Images With Webbrowser
icString is a constant that defines the Inet control to open the page as string text. sScr is a variable to hold the parsed image location.
You could set your browser to navigate to "http://www.maporama.com/affiliates/shellza/share/map.asp?SEARCH_ADDRESS.x=0&COUNTRYCODE=ZA&SESSIONID=6C164693-6C0F-48B5-B3FA-E0FF20B64397&_XgoGCTownName=Sandton&Zip=&_XgoGCAddress=&x=15&y=20" and when the page is completely loaded you can search for the image name/location and then use the Inet control to open that location as Binary and download the image to the temp file and use LoadImage into the picturebox.
Re: Grabbing Images With Webbrowser
OK thanx guys!
Now how do I go about parsing the location of that image because it doesnt end in a regular .jpg or .gif extension.
I really appreciate any help,
Re: Grabbing Images With Webbrowser
I dont think your going to be able to do this as the page is an ASP page and the image is rendered only if you have a current valid session variable id initiatedfrom the initial page. Its probably for preventing people from using its images :D
This is the location of the map picture and as you can see it has the session variable and other parameters passed to create the image map.
<td class="2pixBorder"><input type="image" border="0" name="XgoClickMap" align="center" src="../image.asp?XgoPageName=XMLOUT&XgoUserID=1F2A8BEBF4148E4&XgoNbReq=3&XgoAnswer=Gif&size x=370&sizey=263&CODE=lieue" title="Click to recenter" width="370" height="263"></td>
1 Attachment(s)
Re: Grabbing Images With Webbrowser
Those are dynamic picture names. Here is the one for Sandton.
I used the DOM Inspector in Firefox and clicked on the image.
Here's what i found in the source:
Quote:
<tr>
<td class="2pixBorder"><input type="image" border="0" name="XgoClickMap" align="center" src="../image.asp?XgoPageName=XMLOUT&XgoUserID=74642A63405F4107&XgoNbReq=1&XgoAnswer=Gif&siz ex=370&sizey=263&CODE=lieue" title="Click to recenter & zoom in" width="370" height="263"></td>
<td valign="top" bgcolor="FFC100" class="2pixBorder">
<table width="100%" height="100" border="0" cellpadding="0" cellspacing="0">
<tr>
Re: Grabbing Images With Webbrowser
Thats the same picture name I posted in #9. I also mentioned its dynamic depending on the sessions variable that is also passed.
Re: Grabbing Images With Webbrowser
Didn't see it when I started the post. Decided to use the Inspector, and got hung up saving it. Then I used source.
Re: Grabbing Images With Webbrowser
11 minutes? Anyways...
What you can do is use the inet control set to the initial page and populate the city name and submit. Then in the resulting page parse out the session id and save to a variable. Then connect using the inet control again to the image location passing the session id and image parameters. Then Put it to a system file and load to your picturebox control. Not very pretty but it may work.
Re: Grabbing Images With Webbrowser
OK, I can do that. How will I get the image parameters?
thnx
Re: Grabbing Images With Webbrowser
Like I posted you need to parse out the properties. you can use Instr and Mid$ and Len to do it. This is the part you want...
VB Code:
src="../image.asp?XgoPageName=XMLOUT&[b]XgoUserID=[/b]1F2A8BEBF4148E4&[b]XgoNbReq=[/b]3&[b]XgoAnswer=[/b]Gif&[b]sizex=[/b]370&[b]sizey=[/b]263& CODE=lieue" title="Click to recenter" width="370" height="263">
Re: Grabbing Images With Webbrowser
XgoUserID=1F2A8BEBF4148E4 is the session parameter value that will change between runs.
Not too sure what this one is for: XgoNbReq=3
This is the image extension: XgoAnswer=Gif
Image properties: sizex=370&sizey=263&
Re: Grabbing Images With Webbrowser
Thanx a lot RobDog888!
One last question: what is the absolute location for that ".../image.asp?..."??
Thanx a lot!
Re: Grabbing Images With Webbrowser
That's the Active Server Page on the webserver. You cannot access it directly, without passing it the other information. You could have your program fill out the first page and click the button though.
Re: Grabbing Images With Webbrowser
Yes but once I've rendered the image and gotten the ID of the image what goes before the "..." as the location of where the image.asp page is located
Re: [RESOLVED] Grabbing Images With Webbrowser
Well the original question has been resolved, thanx!
Re: [RESOLVED] Grabbing Images With Webbrowser
Is there any way to capture or save dynamic image from a webBrowser control