Menu Close

When invoking ONVIFSnapshot, how to get the JPEG data from the OnRawVideoSample event in VB.NET?

How Can We Help?

< Back

Private Sub Button_Click(ByVal sender As Object, ByVal e As System.EventArgs)
 VideoGrabber1.OpenURLAsync = False  ‘ True for asynchrone capture
 VideoGrabber1.SetAuthentication(VidGrab.TAuthenticationType.at_IPCamera, “user”, “password”)
 VideoGrabber1.IPCameraURL = “onvif://”
 AddHandler VideoGrabber1.OnRawVideoSample, AddressOf OnRawVideoSample_JpegSnapshot
 VideoGrabber1.ONVIFSnapShot(True, False, “”)
End Sub

Private Sub OnRawVideoSample_JpegSnapshot(sender As Object, e As VidGrab.TOnRawVideoSampleEventArgs)
 If e.formatType = VidGrab.TFormatType.ft_Unknown Then
  Dim JpgImg(e.sampleDataLength) As Byte

  Dim i As Integer
  For i = 0 To e.sampleDataLength – 1
    JpgImg(i) = Marshal.ReadByte(e.pSampleBuffer, i)

  Dim oFileStream As System.IO.FileStream
  oFileStream = New System.IO.FileStream(“snapshot.jpg”, System.IO.FileMode.Create)
  oFileStream.Write(JpgImg, 0, e.sampleDataLength)
 End If
End Sub

Table of Contents