AForge.Video - 相机未居中

时间:2016-05-11 00:33:14

标签: vb.net camera aforge

我正在使用AForge.Video在我的笔记本电脑中使用相机。 但为什么相机拍摄的视频不居中?

以下是我的代码:

 Dim videoDevices As FilterInfoCollection
 Dim videoSource As VideoCaptureDevice
 videoDevices = New FilterInfoCollection(FilterCategory.VideoInputDevice)
 videoSource = New VideoCaptureDevice(videoDevices(0).MonikerString)
 AddHandler videoSource.NewFrame, AddressOf Me.video_NewFrame

  Sub video_NewFrame(sender As Object,
        eventArgs As NewFrameEventArgs)

        Dim bitmap As Bitmap
        Try

            bitmap = eventArgs.Frame
            If Not bitmap Is Nothing Then


                PictureBox1.Image = DirectCast(bitmap.Clone(), Bitmap)
                PictureBox1.Refresh()
            End If

        Catch

        End Try
    End Sub

谢谢!

1 个答案:

答案 0 :(得分:0)

我不相信我明白你的意思"相机不居中"但我知道最好使用AForge Clone()来抓取video_NewFrame事件处理程序中的框架

bitmap = AForge.Imaging.Image.Clone(eventArgs.Frame);

并确保PictureBox1 sizemode属性设置为" StretchImage"