i trying build camera app. able take photo , save it.
but heres twist. if save photo in applicationdata.current.localfolder , able display in image control. when save in knownfolders.cameraroll image control doesnt load photo.
the photo displayed in phone's gallery (photos), not file not created. i've added pictures library capability too. theres not exception!
async private void capture_photo_click(object sender, routedeventargs e) { //create jpeg image encoding format storing image in jpeg type imageencodingproperties imgformat = imageencodingproperties.createjpeg(); //create storage file in local app storage //storagefile file = await applicationdata.current.localfolder.createfileasync("photo.jpg",creationcollisionoption.replaceexisting); //// create storage file in picture library storagefile file = await knownfolders.cameraroll.createfileasync("photo.jpg", creationcollisionoption.generateuniquename); // take photo , store on file location. await capturemanager.capturephototostoragefileasync(imgformat, file); // photo bitmapimage using storage file path. bitmapimage img = new bitmapimage(); bitmapimage bmpimage = new bitmapimage(new uri(file.path)); // show captured image on image uielement. imagepreivew.source = bmpimage; }
it's different when access file picturlibrary. need load file stream required access mode calling storagefile.openasync(fileaccessmode).
change code following work:
async private void capture_photo_click(object sender, routedeventargs e) { //create jpeg image encoding format storing image in jpeg type imageencodingproperties imgformat = imageencodingproperties.createjpeg(); //create storage file in local app storage //storagefile file = await applicationdata.current.localfolder.createfileasync("photo.jpg",creationcollisionoption.replaceexisting); //// create storage file in picture library storagefile file = await knownfolders.cameraroll.createfileasync("photo.jpg", creationcollisionoption.generateuniquename); // take photo , store on file location. await capturemanager.capturephototostoragefileasync(imgformat, file); var picstream = await file.openasync(windows.storage.fileaccessmode.read); bitmapimage img = new bitmapimage(); img.setsource(picstream); imagepreivew.source = img; }
Comments
Post a Comment