Răspuns Saving images

  • Friday, April 03, 2009 3:10 PM
     
     
    Is there a way to save an image to a file on the hard drive?  You can get a picture "object" by pic = Flickr.GetRandomPicture("lightning" ), but there doesn't seem to be a way to save it.  I have tried the File.WriteContents("c:\whatever\file.jpg",pic) approach, but this doesnt seem to work...
    Thanks for any help,
    Frank

All Replies

  • Friday, April 03, 2009 3:46 PM
    Moderator
     
     
    Check out Network.DownloadFile
  • Friday, April 03, 2009 4:50 PM
     
     
    Thanks, Vijaye.
    Looks like it works great for known urls.
    Are there any examples?
    Thanks,


  • Friday, April 03, 2009 5:29 PM
    Moderator
     
     Answered
    Here's an example of downloading a Flickr image to the local machine, and print out the file path.

      pic = Flickr.GetRandomPicture("whale")
      localFile = Network.DownloadFile(pic)
      TextWindow.WriteLine("Local path: " + localFile)

    You can then use File.CopyFile to copy the downloaded file to wherever you want.

      pic = Flickr.GetRandomPicture("whale")
      localFile = Network.DownloadFile(pic)
      TextWindow.WriteLine("Local path: " + localFile)
      File.CopyFile(localFile, "c:\pic.jpg")