vb 数组 Winsock1收发图片
发布网友
发布时间:2024-04-04 05:26
我来回答
共3个回答
热心网友
时间:2024-06-12 22:18
发送端:
Private Sub Winsock1_Connect()
Print "connect"
Dim BB() As Byte
'图片Picture1读入BB
Dim PBag As New PropertyBag
PBag.WriteProperty "Picture", Picture1.Picture
BB = PBag.Contents
'Winsock1.SendData PBag.Contents
Set PBag = Nothing
Dim k As Long
k = UBound(BB) '计算长度
ReDim Preserve BB(LBound(BB) To UBound(BB) + 4) As Byte
Dim l As Long
For l = UBound(BB) To LBound(BB) + 4 Step -1
BB(l) = BB(l - 4)
Next l
'保存长度
BB(0) = k Mod 256
k = k \ 256
BB(1) = k Mod 256
k = k \ 256
BB(2) = k Mod 256
k = k \ 256
BB(3) = k Mod 256
Winsock1.SendData BB '发送整个二进制
DoEvents
End Sub
------------------------
接收端
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Static l As Long
Dim bb() As Byte
Static tmp() As Byte
Static k As Long
Dim prp() As Byte
Winsock1.GetData bb
Dim i As Long
If l = 0 Then
l = bb(3) * 256& * 256 * 256 + bb(2) * 256& * 256 + bb(1) * 256& + bb(0) + 1
ReDim tmp(1 To l) As Byte
k = 1
i = 4
End If
For i = i To UBound(bb)
tmp(k) = bb(i)
k = k + 1
Next i
If k >= l Then
l = 0
k = 0
Dim PBag As New PropertyBag
PBag.Contents = tmp
Set Picture1.Picture = PBag.ReadProperty("Picture")
End If
End Sub
不明白的百度HI我
热心网友
时间:2024-06-12 22:15
1
热心网友
时间:2024-06-12 22:18
分多次发
如果要例子我这里有