2016-08-19 2 views
0

보호 된 메모리를 읽거나 쓰려고 시도했습니다. 다른 메모리가 손상되었다는 표시 인 경우가 종종 입니다.AccessViolationException 처리되지 않았습니다. [VB.Net] [Emgucv]

이미지를 내 PictureBox에 설정하면 오류가 발생했습니다. 그것의 잘 작동하지만 나중에 오류 팝업에.

여기 내 코드입니다.

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick 
    Try 
     Dim cap As New Capture() 'first line 

     PictureBox1.Image = cap.QueryFrame.ToBitmap 'this line AccessViolationException 
    Catch ex As Exception 
     Timer1.Stop() 
     MsgBox("CAMERA ERROR " & ex.Message) 
    End Try 
End Sub 

Private Sub MetroTile1_Click(sender As Object, e As EventArgs) Handles MetroTile1.Click 
     Try 
      Dim cap As New Capture() 'first line 
      Select Case MetroTile1.Text 
       Case "Capture" 
        Timer1.Start() 
        MetroTile1.Text = "OK" 
       Case "OK" 
        Timer1.Stop() 
        frmStudentAddEdit.picImage.Image = PictureBox1.Image 
        MetroTile1.Text = "Capture" 
        Me.Close() 
      End Select 
     Catch ex As Exception 
      Timer1.Stop() 
     End Try 
    End Sub 

cap.QueryFrame.ToBitmapAccessViolationException 오류가 처리되지 않은이었다이다.

어떻게 해결할 수 있습니까? 이 오류의 원인은 무엇입니까? 도와주세요.

+0

교체 후 폐기 형태 (만들지 새로운마다)의 멤버이지만 timer가 틱 할 때마다 새로운 Capture를 생성하는 것이 놀랍습니다. 예제를 참고하고이 올바른지 확인하십시오. 또한 비트 맵 처리가 끝나면 비트 맵을 삭제해야합니다. – FloatingKiwi

+0

캠에서 이미지를 캡처 한 후에는 어떻게 비트 맵을 처리 할 수 ​​있습니까? 미안 vb.net에 아직도 hardwares에 새로운. – TKGhoul

답변

0

다음과 같은 것을 목표로 삼으십시오.

  1. 캡처,
  2. 가 oldImage는 I 전에이 라이브러리를 사용하지 않는 한

Private mCapture As Capture 

Private Sub Form12_Load(sender As Object, e As System.EventArgs) Handles Me.Load 
    mCapture = New Capture() 
End Sub 

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick 
    Try 
     Dim oldImage = PictureBox1.Image 
     Dim newFrame = mCapture.QueryFrame.ToBitmap 
     PictureBox1.Image = newFrame.ToBitmap 
     If oldImage IsNot Nothing Then oldImage.Dispose() 
    Catch ex As Exception 
     Timer1.Stop() 
     MsgBox("CAMERA ERROR " & ex.Message) 
    End Try 
End Sub 

Private Sub MetroTile1_Click(sender As Object, e As EventArgs) Handles MetroTile1.Click 
    Try 
     Select Case MetroTile1.Text 
      Case "Capture" 
       Timer1.Start() 
       MetroTile1.Text = "OK" 
      Case "OK" 
       Timer1.Stop() 
       frmStudentAddEdit.picImage.Image = PictureBox1.Image 
       MetroTile1.Text = "Capture" 
       Me.Close() 
     End Select 
    Catch ex As Exception 
     Timer1.Stop() 
    End Try 
End Sub 
+0

제 경우에는 작동합니다! 감사합니다!! 건배! – TKGhoul

관련 문제