c# - UWP/Windows Phone Apps System resource management -
i writing uwp app makes use of camera snap photo. when run app on phone able snap photo. there few bugs, of think can work out, big problem occurs when try use stock camera app after suspending app. if explicitly terminate camera app have no problem using stock camera app. far i've tested on lumia 830 , lumia icon , both phones struggle launch stock camera app , both unable save picture after picture taken. have noticed similar problem media player on every windows phone have owned. if using podcast app , try switch spotify app phone struggles make transition system resources 1 app app. there way release phone's camera resources when app suspended. here snippet of event handler using snap picture:
private async void camerabutton_click(object sender, routedeventargs e) { cameracaptureui snapphoto = new cameracaptureui(); snapphoto.photosettings.format = cameracaptureuiphotoformat.png; snapphoto.photosettings.allowcropping = true; snapphoto.photosettings.croppedaspectratio = new size(1000, 1000); storagefile photofile; photofile = await snapphoto.capturefileasync( cameracaptureuimode.photo); if (photofile == null) { return; } else { canvastextformat textformat = new canvastextformat() { fontsize = 20, fontfamily = "arial", direction = canvastextdirection.lefttorightthentoptobottom, }; canvasdevice mycanvasdevice = canvasdevice.getshareddevice(); canvasbitmap mycanvasbitmap; datetime today = datetime.now; using (irandomaccessstream stream = await photofile.openasync(fileaccessmode.read)) { mycanvasbitmap = await canvasbitmap.loadasync(mycanvasdevice, stream); } canvasrendertarget offscreenpallet = new canvasrendertarget(mycanvasdevice, 1000, 1250, 96); using (canvasdrawingsession sesssion = offscreenpallet.createdrawingsession()) { sesssion.clear(colors.black); sesssion.drawimage(mycanvasbitmap, 0, 0); sesssion.drawtext(today.tostring("d"), new vector2(900, 1120),colors.white, textformat); sesssion.drawtext(string.format("weight: {0}lbs.", app.userdata.weight.tostring()), new vector2(10, 1120), colors.white, textformat); sesssion.drawtext(string.format("body fat: {0}%", bodyfatpercentage), new vector2(10, 1150), colors.white, textformat); sesssion.drawtext(string.format("{0} pounds of fat", math.round((bodyfatpercentage / 100) * app.userdata.weight,2)), new vector2(817, 1150), colors.white, textformat); } mycanvasbitmap = offscreenpallet; using (irandomaccessstream savestream = await photofile.openasync(fileaccessmode.readwrite)) { bitmapencoder encoder = await bitmapencoder.createasync(bitmapencoder.pngencoderid, savestream); encoder.setpixeldata(bitmappixelformat.bgra8, bitmapalphamode.ignore, (uint)offscreenpallet.bounds.width, (uint)offscreenpallet.bounds.height, 96, 96, offscreenpallet.getpixelbytes()); await encoder.flushasync(); } question.visibility = visibility.collapsed; results.visibility = visibility.collapsed; selfy.visibility = visibility.visible; bitmapimage selfybitmap = new bitmapimage(); storagefile savedpic = await photofile.copyasync(knownfolders.pictureslibrary,"progress pic.png", namecollisionoption.generateuniquename); using (irandomaccessstream loadnewimage = await photofile.openasync(fileaccessmode.read)) { await selfybitmap.setsourceasync(loadnewimage); } selfy.source = selfybitmap; await photofile.deleteasync(); } }
Comments
Post a Comment