示例#1
0
 private void StartSessionCompleted(IAsyncResult a)
 {
     try
     {
         if (a.AsyncState.Equals(1))
         {
             phoneService.EndStartSession(a);
             cam.PreviewFrameAvailable += cam_PreviewFrameAvailable;
         }
         else
         {
             phoneService.BeginStartSession(DateTime.UtcNow.GetUnixTimestamp() - App.TimeDifference,
                                            (int)resolution.Width, (int)resolution.Height, StartSessionCompleted, 1);
         }
     }
     catch (Exception e)
     {
         Dispatcher.BeginInvoke(new Func <Exception, string>(exc => txtDebug.Text = exc.Message), e);
     }
 }
示例#2
0
        //Code for initialization, capture completed, image availability events; also setting the source for the viewfinder.
        protected async override void OnNavigatedTo(NavigationEventArgs e) //当页面变为框架中的活动页面时调用。
        {
            var resolutions = PhotoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back);

            resolution = resolutions.Aggregate((x, y) => x.Height * x.Width < y.Height * y.Width ? x : y);

            resolutionsListBox.ItemsSource = resolutions;

            EndpointAddress address;

            if (App.LocalAddress.StartsWith("192.168"))
            {
                address = new EndpointAddress("http://192.168.173.1:8000/phone");
            }
            else
            {
                address = new EndpointAddress("http://desk.gqqnbig.me:8000/phone");
            }
            factory = new ChannelFactory <IPhoneService>(new BasicHttpBinding(), address);
            //factory.Opened += factory_Opened;
            phoneService         = factory.CreateChannel(address);
            imageSeqeuenceNumber = 0;

            if (PhotoCaptureDevice.AvailableSensorLocations.Contains(CameraSensorLocation.Back))
            {
                cam = await PhotoCaptureDevice.OpenAsync(CameraSensorLocation.Back, resolution);

                phoneService.BeginStartSession(DateTime.UtcNow.GetUnixTimestamp() - App.TimeDifference, (int)resolution.Width, (int)resolution.Height,
                                               StartSessionCompleted, 0);
                cam.SetProperty(KnownCameraPhotoProperties.FlashMode, FlashState.Off);
                //cam.SetProperty(KnownCameraPhotoProperties.SceneMode, CameraSceneMode.Landscape);
                cam.SetProperty(KnownCameraGeneralProperties.AutoFocusRange, AutoFocusRange.Infinity);
                cam.SetProperty(KnownCameraPhotoProperties.LockedAutoFocusParameters, AutoFocusParameters.Focus);

                await cam.SetPreviewResolutionAsync(resolution);

                viewfinderBrush.SetSource(cam);

                //CameraButtons.ShutterKeyPressed += ShutterButton_Click;
            }
            else
            {
                MessageBox.Show("Camera is not available. Exiting...");
                Application.Current.Terminate();
                return;
            }

            //var videoCaptureDevice = await AudioVideoCaptureDevice.OpenAsync(CameraSensorLocation.Back, AudioVideoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back).First());

            //videoCaptureDevice.SetProperty(KnownCameraAudioVideoProperties.VideoTorchMode, VideoTorchMode.On);
            //videoCaptureDevice.sta



            PhoneApplicationService.Current.ApplicationIdleDetectionMode = IdleDetectionMode.Disabled;



            //timer = new DispatcherTimer();
            //timer.Interval = TimeSpan.FromSeconds(0.2);
            //timer.Tick += (sender, e1) =>
            //{
            //    ShutterButton_Click(null, null);
            //};
            //timer.Start();
        }