Development apps often store pictures on the web, In 8.1 have filesavepicker can use, but the user reflects every time to choose the path good trouble, so began to look for the method of direct storage to the photo library, the first sure to get the picture stream from the network, and then create a new file in the picture library, the picture flow to the file to be finished, all kinds of MSDN after finally resolved, not many said On the Code
stringFileName ="Picture"+datetime.now.ticks+". jpg"; //Create an empty file under the Savepictures folder to save the pictureStorageFile Destinationfile =awaitKnownFolders.SavedPictures.CreateFileAsync (FileName, creationcollisionoption.replaceexisting); using(varResponse =awaithttpwebrequest.create (Savepictureinfo.imageuri). Getresponseasync ()) {//get to Picture stream using(Stream Responsestream =Response. GetResponseStream ()) {using(varDestinationstream =awaitDestinationfile.openasync (Fileaccessmode.readwrite)) { using(varDestinationoutputstream = Destinationstream.getoutputstreamat (0)) { awaitRandomaccessstream.copyandcloseasync (Responsestream.asinputstream (), destinationstream); } } } //get file update statusFileupdatestatus status =awaitCachedfilemanager.completeupdatesasync (destinationfile); if(Status = =fileupdatestatus.complete) {stringsave_success = loader. GetString ("usavesuccess"); await NewMessagedialog (save_success). Showasync (); } Else { stringsave_failed = loader. GetString ("usavefailed"); await NewMessagedialog (save_failed). Showasync (); }
Just learn WP soon, if there is a mistake, please correct me.
[WP8.1 Development] Download images from the network directly into the phone photo gallery