vb 数组 Winsock1收发图片

'工程1
Private Sub Timer1_Timer() '发送Picture1中的图片
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
Winsock1.SendData BB '发送整个二进制
DoEvents
End Sub

'工程2 这个工程要怎么写才能正常发到图片
Private Sub Winsock1_DataArrival(Index As Integer, ByVal bytesTotal As Long) '来信
Dim Bf As Byte
Winsock1(List1.Text).GetData Bf, vbByte + vbArray ' 接收Winsock1(List1.Text)发来的图片

If UBound(BB) >= "这里应是什么?" Then '因为Winsock1一次只能收到8000多字节,这里是个大问题
Dim PBag As New PropertyBag
PBag.WriteProperty "Picture", Picture1.Picture
PBag.Contents = Bf
Picture1.Picture = PBag.ReadProperty("Picture")
Set PBag = Nothing
End If
End Sub
接收时不要写入硬盘,这样我也会,我想要的是用代码就完成,不要写入硬盘临时文件

发送端:
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我
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-07-25
分多次发

如果要例子我这里有
第2个回答  2010-07-25
1
相似回答