远程监控视频的传输优化VB.NET

前端之家收集整理的这篇文章主要介绍了远程监控视频的传输优化VB.NET前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Private sckConnect As New Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp)
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

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

End Sub

原文链接:https://www.f2er.com/vb/263154.html

猜你在找的VB相关文章