Announcement

Collapse
No announcement yet.

Help sending URL to browser then screen capture

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help sending URL to browser then screen capture

    Howdy, I would like to send a series of URLs to a browser (chrome for example) then capture the screen after the URL loads for a mapping application. This is in PBCC. Any pointers in the right direction or suggestions are appreciated.

  • #2
    So you want it first rendered in a browser and then you will capture a screen image? It's pretty straightforward to get the HTML text of a web page and there are many examples here of doing just that. Maybe you can parse out what you need from the HTML without rendering an image?



    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Larry,

      Do you mean "mapping" literally? (like image with roads and/or geo contours)
      Dale

      Comment


      • #4
        By "send a series of URLs", do you mean you mean send a single page URL to a browser, capture the window once the browser displays the result, save the image and repeat?

        Presumably your URLs are to web pages or to a script that generated an image with different parameters for the various images, not to image files?

        Your main issue in automating that would be in knowing when the browser had completed loading the page.

        A bit more detail on your URLs, the desired images, your "mapping application" and hhow automated you want this would help.

        MCM recent comment in another thread comes to mind:
        "Amazing what happens when you ask for ideas how to accomplish some specific task rather than for help with a technique or method you have already selected, isn't it?​"

        Comment


        • #5
          Hi all,

          MCM- yes I want the browser to load the url then I want to capture the screen image, not a HTML scrape. I do know how to get a scrape and have done that previously.

          now that you point that out I guess since I have loaded pages for scrapes, I can use the same procedure to load the url that produces the image.

          Stuart and Dale - I am looking to load map images of approximate size 1 degree latitude by 1 degree longitude and capture the image then splice them together into a large single image.

          So now I think I know how to load the URL I want and how to know when it’s done rendering by getting the html response. I’m just lacking the info on getting the screen capture and saving those image files.

          thanks!

          Comment


          • #6
            Larry,
            From which source?
            Google Maps
            MapQuest
            Microsoft Bing Maps
            OpenStreetMap
            Other?

            They may already have an API or a direct HTTP request to get a Tile or Tiles of the magnitude you want, in PNG, JPG, SVG etc.

            Comment


            • #7
              For Example you can Use a free Developer Basic, Bing Map API Key that allows to get 125000 request per year
              To get a key you need to got to https://www.bingmapsportal.com
              either use an existing MS Account, or create one.


              and use it like this. to save the PNG. See sample code.

              https://dev.virtualearth.net/REST/V1/Imagery/Map/Road/42.6564%2C-73.7638/13?mapSize=600%2C300&format=png&key=YOUR-API-KEY-HERE

              Code should work both PBCC6 and PBWIN10 (I always use Jose Roca Includes)
              '
              Code:
              #COMPILE EXE    'Jose Roca Includes
              #DIM ALL
              #UNIQUE VAR ON
              
              %Unicode = 1
              
              FUNCTION PBMAIN () AS LONG
               LOCAL sTemp, sBuffer AS STRING
               LOCAL lTemp, lCount AS LONG
              
                File_Save ("map.png" , GetImagefromWEB("https://dev.virtualearth.net/REST/V1/Imagery/Map/Road/42.6564%2C-73.7638/13?mapSize=600%2C300&format=png&key=YOUR-API-KEY-HERE"))
              
                  ? "File saved"
                  #IF %DEF(%PB_CC32)
                     WAITKEY$
                  #ENDIF
              
              END FUNCTION
              
              '-----------------------------------------------
              ' GetImagefromWEB
              ' Get Image from a WEB URL
              '
              #INCLUDE ONCE "httprequest.inc"
              #INCLUDE ONCE "ole2utils.inc"
              '-----------------------------------------------
              FUNCTION GetImagefromWEB (sFullURL AS STRING) AS STRING
                 LOCAL pWHttp AS IWinHttpRequest
                 LOCAL vSTream AS VARIANT
                 LOCAL pIStream AS IStream
                 LOCAL Buffer AS STRING * 8192
                 LOCAL strBuffer AS STRING
                 LOCAL cbRead AS DWORD
                 LOCAL iSucceeded AS INTEGER
                 LOCAL wsHeaders, wTemp1 AS WSTRING
                  sFullURL = TRIM$(sFullURL)      ' just in case remove leading and trailling spaces
                 ' Creates an instance of the HTTP service
                 pWHttp = NEWCOM "WinHttp.WinHttpRequest.5.1"
              
                 IF ISNOTHING(pWHttp) THEN EXIT FUNCTION
                 TRY
                    ' Opens an HTTP connection to an HTTP resource
                    pWHttp.Open "GET", sFullURL
                    ' Sends an HTTP request to the HTTP server
                    pWHttp.Send
                    ' Wait for response with a timeout of 5 seconds
                    iSucceeded = pWHttp.WaitForResponse(5)
                       wsHeaders = pWHttp.GetAllResponseHeaders
                       '? wsHeaders
                    ' Get the response as a stream
                    vStream = pWHttp.ResponseStream                        ' now we get the file and save it
                    IF VARIANTVT(vStream) = %VT_UNKNOWN THEN
                       pIStream = vStream
                       vStream = EMPTY
                       ' Read the stream in chunks
                       DO
                          pIStream.Read VARPTR(buffer), SIZEOF(buffer), cbRead
                          IF cbRead = 0 THEN EXIT DO
                          IF cbRead < SIZEOF(buffer) THEN
                             strBuffer = strBuffer & LEFT$(buffer, cbRead)
                          ELSE
                             strBuffer = strBuffer & buffer
                          END IF
                       LOOP
                       pIStream = NOTHING
                       IF LEN(strBuffer) THEN
                          FUNCTION = strBuffer
                       ELSE
                          ? "Buffer is empty"
                       END IF
                    END IF
                 CATCH
                    OleShowErrorInfo OBJRESULT
                 END TRY
              END FUNCTION
              '-----------------------------------------------
              ' GetImagefromWEB                            End
              '-----------------------------------------------
              
              FUNCTION File_Save (BYVAL sFileName AS STRING, BYVAL sContent AS STRING)  AS LONG
              '-----------------------------------------------
              ' File_Save
              ' SAVE a complete file from a String Var
              ' if file exists it's replaced
              ' Usage     FILE_Save (sFileName, sContent)
              '-----------------------------------------------
              LOCAL lFileNum AS LONG
              IF ISFILE (sFileName) THEN KILL (sFileName)
              lFileNum = FREEFILE
              OPEN sFileName FOR BINARY AS #lFileNum
              PUT #lFileNum,, sContent
              CLOSE #lFileNum
              END FUNCTION
                ' FILE_Save
              '-----------------------------------------------
              ' FILE_Save                                End
              '-----------------------------------------------
              '

              Comment


              • #8
                The above link with proper API Key gives

                Click image for larger version

Name:	map.png
Views:	92
Size:	321.3 KB
ID:	818822

                Comment


                • #9
                  I shall compare and contrast the two options i see for moving my project forward.

                  Option A
                  - write kludge code to make browser call map url.
                  - somehow monitor status of browser to determine if screen is properly loaded
                  - screen grab map section
                  - write code to edit map section to remove unwanted items like browser title bar, zoom icons etc in the screen grab
                  - figure out how to stitch together these subsections without loosing map details.

                  Or ….

                  Option B
                  -Make API call as shown above to get the exact thing I wanted. By calling Adjacent GPS coordinates the sections will stitch together without any modifications.

                  Conclusion - obviously my pride requires sticking with option A. Haha just kidding. Thank you Rod, I will get an API key and give this a try. I appreciate this.​

                  Comment


                  • #10
                    Or if you need something in a hurry, you could look at Universal Maps Downloader:
                    http://www.allmapsoft.com/umd/

                    Not free, but it does work well.


                    Comment


                    • #11
                      Thanks Ian that looks like a very useful piece of software. I will check it out.

                      Comment

                      Working...
                      X