2012-09-09 1 views
1

나는 C# 프로젝트 작업 중입니다. 그래서 여기에서는 emguCV 이미지 처리 라이브러리를 사용했습니다. 이것은 웹 카메라에 액세스하여 멈추는 샘플 코드입니다. 이 코드는 작동하지만 비디오 장치를 멈 추면 제대로 멈추지 않습니다.비디오 캡처 장치가 올바르게 중지하는 방법

private void btnStart_Click(object sender, EventArgs e) 
    { 
     if(capture==null){ 
      try 
      {      
       capture = new Capture(); 
      } 
      catch(NullReferenceException ex){ 
       MessageBox.Show(ex.Message); 
      } 
     } 

     if(capture!=null){ 
      if (captureInProgress) 
      { 
       btnStart.Text = "!Start"; 
       Application.Idle -= ProcessFrame; 
      } 
      else { 
       btnStart.Text = "Stop"; 
       Application.Idle += ProcessFrame; 
      } 
     } 
     captureInProgress = !captureInProgress; 
    } 

내가 여기에서 놓친 것. 도와주세요.

+0

안녕하세요, 올바르게 중단되지 않았다는 것이 정확히 무엇입니까? 장치를 해제하려면 캡처 변수 자체를 처리해야합니다. capture.Dispose(); 건배 – Chris

+0

dispose()를 추가했지만 이후에는 예외가 표시됩니다. 제발 그 코드를 사용하여 그 일을 보여줄 수 있습니다. @ Chris – mssb

+0

실제로 여기에 작업 (위의 emguCV 라이브러리를 사용하여) 위의 중지 후 Afroge 라이브러리를 사용하여 동일한 웹 캠에 액세스하려고합니다.이 설명을 충분히 명확한가요? 내게 해결책을주세요. @Chris – mssb

답변

0
private void btnStart_Click(object sender, EventArgs e) 
    { 
     if(capture==null){ 
      try 
     {      
      capture = new Capture(); 
     } 
     catch(NullReferenceException ex){ 
      MessageBox.Show(ex.Message); 
     } 
    } 

    if(capture!=null){ 
     if (captureInProgress) 
     { 
      btnStart.Text = "!Start"; 
      capture.Stop(); //you miss this 
      Application.Idle -= ProcessFrame; 
     } 
     else { 
      btnStart.Text = "Stop"; 
      capture.Start(); //you miss this 
      Application.Idle += ProcessFrame; 
     } 
    } 
    captureInProgress = !captureInProgress; 
} 
+1

코드 줄을 언급하고 더 중요한 것은 * 왜 * 필요한 코드 줄을 언급하면 ​​대답은 더 좋을 것입니다. –

+0

그가 코멘트를 쓴 라인을 보자. // 당신이 이것을 놓친다. – gonzobrains

+0

나는 Stop() 메소드를 사용하고 ProcessFrame 이벤트 핸들러를 제거하지만 여전히 예외가 발생한다. – gonzobrains