远程视频传输可以采用线程下载、图片压缩,还可以考虑先储存进数据库中
Private sckConnect As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) VB.Net远程监控视频的传输优化
Private RemoteIp As IPEndPoint
Private thd As Thread
Private blnExt As Boolean = True
Private _Quality As Int16 = 50
Public WriteOnly Property Quality() As Int16 ’这个函数表示服务器要求的图片质量
Set(ByVal value As Int16)
_Quality = value
End Set
End Property
Private Sub run()
Dim byt() As Byte
Dim stream As MemoryStream
Dim bmp As Bitmap
While blnExt
Try
bmp = getGrcToBmp() '这是获取图片
stream = New MemoryStream
Compress(bmp, stream, _Quality) '这里对图片进行压缩函数
byt = stream.ToArray
sckConnect.Send(byt, byt.Length, SocketFlags.None)
byt.Initialize()
stream = Nothing
Thread.Sleep(30) '30毫秒,也就是1秒中传送33次图片
Catch ex As Exception
Call Ext()
End Try VB.Net远程监控视频的传输优化
End While
End Sub
Public Sub Send(ByVal ip As String, ByVal port As Integer) '服务器的IP和Port
Try
RemoteIp = New IPEndPoint(IPAddress.Parse(ip), port)
sckConnect.SendTimeout = 100
sckConnect.Connect(RemoteIp)
If sckConnect.Connected Then
thd = New Thread(AddressOf run)
thd.Start()
End If
Catch ex As Exception
MsgBox(ex.Message)
Exit Sub
End Try
End Sub
Public Sub Ext()
Try
blnExt = False
thd = Nothing
sckConnect.Disconnect(True)
sckConnect.Close()
Catch ex As Exception
End Try
VB.Net远程监控视频的传输优化
End Sub