2016-08-19 46 views
0

试图读取或写入受保护的内存。这通常是指示其他内存已损坏的 。AccessViolationException未处理[VB.Net] [Emgucv]

这是将图像设置为我的图片框后的错误。它的工作正常,但后来的错误只是弹出。

这是我的代码。

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

我还没有使用过该文库之后布置的形式(不创建新每次)的一员,但每当计时器滴答时,我都会惊奇地发现你正在创建一个新的Capture。请查看示例并检查这是否正确,并确保在完成位置后处理位图 – FloatingKiwi

+0

一旦我从凸轮中捕获图像,如何处理位图。对于vb.net来说,对于硬件来说还是很抱歉。 – TKGhoul

回答

0

瞄准下面的东西。

  1. Capture是
  2. oldImage正在取代

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