2017-11-06 2 views
0

UWP 응용 프로그램을 개발 중입니다. 내 페이지 중 하나는 실제로 사용자가 사진을 찍을 수 있도록하기위한 것입니다. 이 페이지에는 사용자가 사진을 찍기 전에 선택할 타이머가 있습니다.UWP의 카메라 타이머 애니메이션

그러나 타이머를 카메라 화면에서 카운트 다운하면 사진을 찍기 전에 준비 시간이 얼마 남았는지 알 수 있습니다.

어떻게 할 수 있습니까? 고맙습니다!

private async void PhotoButton_Click(object sender, RoutedEventArgs e) 
    { 
     //If preview is not running, no preview frames can be acquired 
     if (!_isPreviewing) return; 

     await Task.Delay(TimeSpan.FromSeconds(_seconds)); 
     await TakePhotoAsync(); 
     await GetPreviewFrameAsSoftwareBitmapAsync(); 

     PreviewFrameBackground.Visibility = Visibility.Visible; 

    } 

private void Timer_3sec_Click(object sender, RoutedEventArgs e) 
    { 
     Timer_5sec.Opacity = 0.2; 
     Timer_7sec.Opacity = 0.2; 
     Timer_3sec.Opacity = 1.0; 
     _seconds = 3; 


    } 
    private void Timer_5sec_Click(object sender, RoutedEventArgs e) 
    { 
     Timer_3sec.Opacity = 0.2; 
     Timer_7sec.Opacity = 0.2; 
     Timer_5sec.Opacity = 1.0; 
     _seconds = 5; 

    } 

    private void Timer_7sec_Click(object sender, RoutedEventArgs e) 
    { 
     Timer_3sec.Opacity = 0.2; 
     Timer_5sec.Opacity = 0.2; 
     Timer_7sec.Opacity = 1.0; 
     _seconds = 7; 

    } 
+0

[DispatcherTimer] (https://msdn.microsoft.com/en-us/library/system.windows.threading.dispatchertimer (v = vs.110) .aspx)는 어떻게됩니까? – TheTanic

+0

전에 DispatcherTimer를 사용 해보지 않았습니다 ... 간단한 데모를 보여 주면 가능합니까? 나는 정말로 감사 할 것이다. 고맙습니다! – thalassophile

+0

내 대답을 확인하십시오 – TheTanic

답변

1

당신은 당신의 문제를 해결하기 위해 DispatcherTimer을 사용할 수 있습니다 :이 필요 이런 경우에

, 여기에 타이머와 테이크 사진 버튼에 대한 내 코드입니다. (! 샘플은 단지 그들을 계산, 캡처을하거나 남은 초를 표시하는 방법을 보여 그나마) 여기
당신이 그렇게 할 수있는 방법을 조금 코드 샘플

클래스 매개 변수 :

private int _startTime; 
private DispatcherTimer _timer = new DispatcherTimer(); 

방법 :

private void StartTimer() 
     { 
      _timer.Interval = TimeSpan.FromMilliseconds(500); 
      _timer.Tick += Timer_Tick; 
      _startTime = Environment.TickCount; 
      _timer.Start(); 
     } 

private void Timer_Tick(object sender, object e) 
     { 
      var remainingSeconds = _seconds - TimeSpan.FromMilliseconds(Environment.TickCount - _startTime).Seconds; 

      if(remainingSeconds <= 0) 
      { 
       _timer.Stop(); 
       _timer.Tick -= Timer_Tick; 
       timerText.Text = "0 Seconds"; 
       //Capture Image 
      } else 
      { 
       timerText.Text = "" + remainingSeconds + " Seconds"; 
      } 

     } 

당신은 _seconds을 설정 한 후 클릭 방법에 StartTimer -Method를 호출해야합니다.

+0

정말 고마워요! 하지만 남은 시간은 어떻게 표시합니까? 이것이 내가이 질문을 게시 한 주된 이유입니다 ... – thalassophile

+0

남은 시간으로 picutres를 만들고 oyur 미리보기 영역에로드하거나 텍스트 상자를 표시합니다. – TheTanic

+0

텍스트 블록에 대해 이렇게 작성합니까? timer.Text = remainingSeconds.ToString(); – thalassophile

관련 문제