c# - Windows Phone camera crashes app when switching between pages -
c# - Windows Phone camera crashes app when switching between pages -
i'm creating simple photographic camera app windows phone 8 in c#. on main view, photographic camera initialized. there button on main view takes separate settings page. however, when press button homecoming main page photographic camera view, app crashes , exception:
an exception of type 'system.invalidoperationexception' occurred in mscorlib.ni.dll not handled in user code
winrt information: unable acquire camera. can utilize class while in foreground.
if there handler exception, programme may safely continued.
this code utilize switch settings page:
private void button_click(object sender, routedeventargs e) { navigationservice.navigate(new uri("/settings.xaml", urikind.relative)); }
and on settings page, utilize button homecoming main page, crash happens.
this code utilize photographic camera initialization:
protected override async void onnavigatedto(navigationeventargs e) { base.onnavigatedto(e); size resolution = photocapturedevice.getavailablecaptureresolutions(camerasensorlocation.back).first();//crashes here photographic camera = await photocapturedevice.openasync(camerasensorlocation.back, resolution); video.setsource(camera); previewtransform.rotation = camera.sensorrotationindegrees; }
the debugger says app crashes on 2nd line in method.
you need dispose photographic camera instance. in page hosting photocapturedevice object:
protected override void onnavigatedfrom(navigationeventargs e) { base.onnavigatedfrom(e); camera.dispose(); }
c# windows-phone-8 camera
Comments
Post a Comment