Ejemplo n.º 1
0
        private void appBarButton_Click(object sender, RoutedEventArgs e)
        {
            if (this.Frame.CanGoBack)
            {
                if (Atimer != null)
                {
                    Atimer.Cancel();
                }
                if (Gtimer != null)
                {
                    Gtimer.Cancel();
                }
                if (Vtimer != null)
                {
                    Vtimer.Cancel();
                }
                if (Ctimer != null)
                {
                    Ctimer.Cancel();
                }
                if (Ftimer != null)
                {
                    Ftimer.Cancel();
                }
                if (Htimer != null)
                {
                    Htimer.Cancel();
                }

                this.Frame.GoBack();
            }
        }
Ejemplo n.º 2
0
        private void btnStop_Click(object sender, RoutedEventArgs e)
        {
            if (Atimer != null)
            {
                Atimer.Cancel();
            }
            if (Gtimer != null)
            {
                Gtimer.Cancel();
            }
            if (Vtimer != null)
            {
                Vtimer.Cancel();
            }
            if (Ctimer != null)
            {
                Ctimer.Cancel();
            }
            if (Ftimer != null)
            {
                Ftimer.Cancel();
            }
            if (Htimer != null)
            {
                Htimer.Cancel();
            }

            combox.IsEnabled   = true;
            combox2.IsEnabled  = true;
            btnStart.IsEnabled = true;
            btnStop.IsEnabled  = false;
        }
Ejemplo n.º 3
0
        private async void takePhoto()
        {
            this.isCapturing = true;

            this.PhotoButton.IsEnabled = false;
            var stream = new InMemoryRandomAccessStream();

            await mediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), stream);

            string[] separators = { ".", ":" };

            string[] time = DateTime.Now.TimeOfDay.ToString().Split(separators, StringSplitOptions.RemoveEmptyEntries);

            //string PHOTO_FILE_NAME = "Photo-" + DateTime.Now.ToString("yyyy-MM-dd-") + time[0] + time[1] + time[2] + ".jpg";
            string PHOTO_FILE_NAME = "Round" + TestRound + "_Photo_" + TestCount + ".jpg";

            try
            {
                captureImage.Source = null;

                photoFile = await KnownFolders.VideosLibrary.CreateFileAsync(
                    PHOTO_FILE_NAME, CreationCollisionOption.GenerateUniqueName);

                ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
                //ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateUncompressed(MediaPixelFormat.Bgra8);
                await mediaCapture.CapturePhotoToStorageFileAsync(imageProperties, photoFile);

                App.ViewModel.readResultFile(PHOTO_FILE_NAME);
                await Task.Delay(2000);

                //照片旋轉
                //await ReencodeAndSavePhotoAsync(stream, photoFile, PhotoOrientation.Rotate270);


                IRandomAccessStream photoStream = await photoFile.OpenReadAsync();

                BitmapImage bitmap = new BitmapImage();
                bitmap.SetSource(photoStream);
                captureImage.Source = bitmap;
            }
            catch (Exception ex)
            {
                Cleanup();
            }
            finally
            {
            }
            this.isCapturing = false;
            Debug.WriteLine("isCapturing" + isCapturing);
            this.PhotoButton.IsEnabled = true;



            if (TestCount >= TestMaxCount)
            {
                Ctimer.Cancel();

                if (TestRound != TestMaxRound)
                {
                    TestRound++;
                    TestCount = 0;

                    await mediaCapture.StopPreviewAsync();

                    mediaCapture.Dispose();
                    mediaCapture = null;
                    Vtimer       = ThreadPoolTimer.CreatePeriodicTimer(Vibrator_Timer_Tick, TimeSpan.FromMilliseconds(7000));
                }
                else
                {
                    TestCount = 0;
                    TestRound = 1;
                    await mediaCapture.StopPreviewAsync();

                    mediaCapture.Dispose();
                    mediaCapture = null;
                    previewElement.Visibility = Visibility.Collapsed;
                    btnStart.IsEnabled        = true;
                    btnStop.IsEnabled         = false;
                    combox.IsEnabled          = true;
                    combox2.IsEnabled         = true;
                    sendresultlog();
                }
            }
        }