【问题标题】:AccessViolationException was unhandled [VB.Net] [Emgucv]AccessViolationException 未处理 [VB.Net] [Emgucv]
【发布时间】:2016-08-20 10:55:33
【问题描述】:

试图读取或写入受保护的内存。这通常是一个 指示其他内存已损坏。

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

这是我的代码。

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 was unhandled 错误。

我该如何解决这个问题?是什么导致了这个错误?请帮忙。

【问题讨论】:

  • 我以前没有使用过这个库,但我很惊讶你每次计时器滴答时都会创建一个新的 Capture。查阅示例并检查是否正确,并确保在完成位图后处理它们
  • 一旦我从 cam 捕获图像后如何处理位图。抱歉,vb.net 还是硬件方面的新手。

标签: vb.net emgucv


【解决方案1】:

目标如下。

  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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-06
    • 1970-01-01
    • 2020-07-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多