最近在研究sdk3000控件,录像和抓拍功能
我学vb.net 刚入门,想用sdk3000控件编写一个视频监控,能够抓拍图像和录像功能。自己写了程序编译后能够显示视频画面,可是在抓拍图片时,总是找不到拍到的图片文件,录像时连视频显示的图像都没了。我把代码贴上,希望高手前辈们能帮忙指点下,告诉小弟到底哪里出错了。这里先谢了程序源代码如下:
‘当串口传输视频时,显示视频画面
Private Sub rs232_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles rs232.DataReceived
'当接收到门口机呼叫大管理机时视频控件显示门口机视频
Dim cardid As Integer = 0
'连接sdk卡进行
AxSDK30001.Connect(cardid, True, AxSDK30001.Width, AxSDK30001.Height)’ 视频初始化
Dim formatecount As Integer
AxSDK30001.GetVideoCompressorCount(formatecount)
Dim i As Integer
Dim buf As New System.Text.StringBuilder
For i = 0 To formatecount - 1
Dim formatName As New String("")
Me.AxSDK30001.GetOneVideoCompressor(i, formatName)
buf.Append(formatName).Append(vbCrLf)
Next
End Sub
Private Sub btn_capturepic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_capturepic.Click
Try
Dim strDir As String = Application.StartupPath & "\picture\"
If IO.Directory.Exists(strDir) = False Then
IO.Directory.CreateDirectory(strDir)
End If
Dim curTime As DateTime = Now
Dim buf As New System.Text.StringBuilder
With curTime
buf.Append(.Year).Append(.Month).Append(.Day).Append(.Hour).Append(.Minute).Append(.Second).Append(.Millisecond)
End With
Dim picFileName As String = "pic_" & curTime.ToString & ".jpg"
Dim picFilePath As String = strDir & picFileName
Dim result As Boolean = Me.AxSDK30001.SaveImageToJpg(picFilePath, 100, 1, True)
If result = False Then
MessageBox.Show("录像拍照失败!请重试!")
Exit Sub
End If
If IO.File.Exists(picFilePath) = False Then ’程序运行时竟没有该图片文件
MessageBox.Show("录像拍照失败,可能是由于录像中无法拍照所致!")
Exit Sub
End If
'更新状态栏,通知拍照成功
Catch ex As Exception
MessageBox.Show("录像拍照失败!请重试!" & vbCrLf & ex.ToString)
End Try
End Sub
‘点录像控件时,图像画面消失
Private Sub btn_getvedio_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_getvedio.Click
Try
Dim strDir As String = Application.StartupPath & "\vedio\"
If IO.Directory.Exists(strDir) = False Then
IO.Directory.CreateDirectory(strDir)
End If
Dim curTime As DateTime = Now
Dim buf As New System.Text.StringBuilder
With curTime
buf.Append(.Year).Append(.Month).Append(.Day).Append(.Hour).Append(.Minute).Append(.Second).Append(.Millisecond)
End With
Dim picFileName As String = "vedio_" & curTime.ToString & ".avi"
Dim picFilePath As String = strDir & picFileName
Dim videoindex As Integer = 2
AxSDK30001.SetCurVideoCompressor(videoindex)
AxSDK30001.SetCurrentAudioCompressorNum(0)
If AxSDK30001.StartCapture(picFilePath, 0) = False Then
Throw New Exception("启动视频录制时返回FALSE")
Else
Throw New Exception("视频控件尚未初始化") '说明视频已经开始捕获了,但是为什么会出现捕获过程中不能连接视频的,接着出现视频没有初始化呢
End If
Catch ex As Exception
MessageBox.Show("录像拍照失败!请重试!" & vbCrLf & ex.ToString)
End Try
End Sub
--------------------编程问答-------------------- 这些东西直接调用系统api就可以了,如果要灵活使用。楼主还需要了解DirectShow的相关知识。 --------------------编程问答-------------------- 自己顶起来! --------------------编程问答-------------------- 我用sdk控件是应该也是可以的吧
--------------------编程问答-------------------- 谢谢你的回复啊 --------------------编程问答-------------------- 重新发次代码看看,排版不好.
Dim cardid As Integer = 0
'连接sdk卡进行
AxSDK30001.Connect(cardid, True, AxSDK30001.Width, AxSDK30001.Height)’ 视频初始化
视频初始化只需要一次吧,不用在DataReceived事件中进行吧,这样每次接收到内容都会重新进行视频初始化 --------------------编程问答-------------------- 问题不是出在视频初始化一次这里吧。这里只是想当接收到视频传送时就能够显示图像
实验中也能够显示串口传到的图片。
我想问一下这是不是由于在不同线程的缘由造成,拍打的图片在保存的文件夹中找不到该图片? --------------------编程问答-------------------- 呵呵 问题解决了
谢谢 !回复的人! --------------------编程问答-------------------- 解决办法贴出来供大家学习啊!
补充:.NET技术 , VB.NET