c# - How to Save and Retrieve BitmapImage using ApplicationData -
in referencing http://tizianocacioppolini.blogspot.com/2014/01/windows-phone-8-folders-and-files.html#.u6ybkfhoxiu trying set sample can gather photo using photochoosertask , save/retrieve photo using appicationdata. ultimate goal save image in folder using new applicationdata
method, , if folder exists remove , replace it. unsure of how set properly
mainpage.xaml.cs
protected override void onnavigatedto(navigationeventargs e) { base.onnavigatedto(e); //if image exists in folder, set image page background using tombstoninghelper.cs retrieve method } private void browse_click(object sender, routedeventargs e) { photochoosertask.show(); } void photochoosertask_completed(object sender, photoresult e) { if (e.taskresult == taskresult.ok) { // file stream , file name stream photostream = e.chosenphoto; string filename = path.getfilename(e.originalfilename); //save image storage using tombstoninghelper.cs } }
tombstoninghelper.cs
public async task storephoto(stream photostream, string filename) { storagefolder folder; //check if folder exists //if folder exists, delete // persist info isolated storage storagefile file = await applicationdata.current.localfolder.createfileasync(filename, creationcollisionoption.replaceexisting); using (stream current = await file.openstreamforwriteasync()) { await photostream.copytoasync(current); } } public async task<bitmapimage> retrievephoto(string filename) { storagefile file = await applicationdata.current.localfolder.getfileasync(filename); stream imagestream = await file.openstreamforreadasync(); //check if file exists // display file image bitmapimage bi = new bitmapimage(); bi.setsource(imagestream); homecoming bi; }
c# windows-phone-8 asynchronous async-await application-data
No comments:
Post a Comment