Save map as image in c:/mydir/

User avatar
sal21
PlatinumLounger
Posts: 4351
Joined: 26 Apr 2010, 17:36

Save map as image in c:/mydir/

Post by sal21 »

Googling...found

Code: Select all

Private Declare Function URLDownloadToFile Lib "urlmon" _
   Alias "URLDownloadToFileA" _
  (ByVal pCaller As Long, _
   ByVal szURL As String, _
   ByVal szFileName As String, _
   ByVal dwReserved As Long, _
   ByVal lpfnCB As Long) As Long

Private Const ERROR_SUCCESS As Long = 0
Private Const BINDF_GETNEWESTVERSION As Long = &H10
Private Const INTERNET_FLAG_RELOAD As Long = &H80000000

Public Function DownloadFile(sSourceUrl As String, _
                             sLocalFile As String) As Boolean

  //'Download the file. BINDF_GETNEWESTVERSION forces 
  //'the API to download from the specified source. 
  //'Passing 0& as dwReserved causes the locally-cached 
  //'copy to be downloaded, if available. If the API 
  //'returns ERROR_SUCCESS (0), DownloadFile returns True.
   DownloadFile = URLDownloadToFile(0&, _
                                    sSourceUrl, _
                                    sLocalFile, _
                                    BINDF_GETNEWESTVERSION, _
                                    0&) = ERROR_SUCCESS

End Function
This query return a image map:

http://dev.virtualearth.net/REST/v1/Ima ... xxxxxxxxxx

User avatar
HansV
Administrator
Posts: 78412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Save map as image in c:/mydir/

Post by HansV »

Have you tried

Code: Select all

DownloadFile "http://dev.virtualearth.net/REST/v1/Imagery/Map/Road/Routes?wp.0=Seattle,WA;64;1&wp.1=Redmond,WA;66;2&key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "C:\MyDir\MyImage.png"
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4351
Joined: 26 Apr 2010, 17:36

Re: Save map as image in c:/mydir/

Post by sal21 »

HansV wrote:
11 Dec 2020, 23:22
Have you tried

Code: Select all

DownloadFile "http://dev.virtualearth.net/REST/v1/Imagery/Map/Road/Routes?wp.0=Seattle,WA;64;1&wp.1=Redmond,WA;66;2&key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "C:\MyDir\MyImage.png"
work!
Sorry for delay...
but i can change the type of picture with .jpg, gif, or ....? or the best is .png?

User avatar
HansV
Administrator
Posts: 78412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Save map as image in c:/mydir/

Post by HansV »

The file in the URL is a .png. The code simply downloads that .png file. You'd have to use a graphics application to save the downloaded .png file in another format such as .jpg.
For many computer images, .png is a very efficient format - it provides a good mix of compression rate and quality. For photos, .jpg is better.
Best wishes,
Hans