从字节TCPCLIENT接收图像 [英] Receive image from byte TCPCLIENT

查看:79
本文介绍了从字节TCPCLIENT接收图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将图像发送到服务器,我注意到它正在接收几个包中的图像,我试图加入缓冲区,但是如果我将图像放在图片框中则不起作用没有加入缓冲区图像不完整

我的项目由几个客户端和一个负责传递imgs的服务器组成


发送Img
< pre lang =vb>
Dim imgMemoryStream As MemoryStream = New MemoryStream()
Dim imgByteArray As Byte()
Imagem.Save(imgMemoryStream,System.Drawing.Imaging.ImageFormat.Jpeg)
imgByteArray = imgMemoryStream .GetBuffer()
serverStream.Write(imgByteArray,0,imgByteArray.Length)
serverStream.Flush()







重新发送Img

  Dim  networkStream  As  NetworkStream = clientSocket.GetStream()
networkStream.Read(bytesFrom, 0 CInt (clientSocket.ReceiveBufferSize))

serverStream.Write(bytesFrom, 0 ,bytesFrom.Length)
serverStream.Flush()



另一位客户收到



  Dim  networkStream  As  NetworkStream = clientSocket.GetStream()
networkStream.Read(bytesFrom, 0 CInt (clientSocket.ReceiveBufferSize))
Dim buffSize As 整数
Dim inStream( 10024 )< span class =code-keyword> As Byte
buffSize = clientSocket.ReceiveBufferSize

serverStream.Read( inStream, 0 ,buffSize)
Dim imgMemoryStream = IO.MemoryStream(img)
PictureBox1.Image = Drawing.Image.FromStream(imgMemoryStream)



任何人都可以给示例 如何 将从服务器发送的字节加入单个变量?

< br $> b $ b

我尝试过:



<$ p $我把它放到客户端发送一条包含图像长度的消息,另一个客户端将接收长度并等待字节,并且将加入一个var,一切顺利,除了加入字节的部分

解决方案

我的解决方案是:



发送Img

  Dim  netStream  As  NetworkStream 
Dim Formatter As IFormatter = BinaryFormatter()
Formatter.Serialize(netStream,img)





收到Img

  Dim  n etStream  As  NetworkStream 
Dim Formatter As IFormatter = BinaryFormatter()
Dim img As Image = Formatter.Deserialize(netStream)





谢谢


I send the image to the server, I noticed that it is receiving the image in several packages, I tried to join the buffers, but it is not working, if I put the image in the picturebox without joining the buffers the image is incomplete

My project consists of several clients and a server that is responsible for passing the imgs


Sending Img
<pre lang="vb">
        Dim imgMemoryStream As MemoryStream = New MemoryStream()
        Dim imgByteArray As Byte()
        Imagem.Save(imgMemoryStream, System.Drawing.Imaging.ImageFormat.Jpeg)
        imgByteArray = imgMemoryStream.GetBuffer()
        serverStream.Write(imgByteArray, 0, imgByteArray.Length)
        serverStream.Flush()




Resending Img

Dim networkStream As NetworkStream = clientSocket.GetStream()
networkStream.Read(bytesFrom, 0, CInt(clientSocket.ReceiveBufferSize))

serverStream.Write(bytesFrom, 0, bytesFrom.Length)
serverStream.Flush()


Another customer receiving

        Dim networkStream As NetworkStream = clientSocket.GetStream()
        networkStream.Read(bytesFrom, 0, CInt(clientSocket.ReceiveBufferSize))
        Dim buffSize As Integer
        Dim inStream(10024) As Byte
        buffSize = clientSocket.ReceiveBufferSize

        serverStream.Read(inStream, 0, buffSize)
        Dim imgMemoryStream = New IO.MemoryStream(img)
        PictureBox1.Image = Drawing.Image.FromStream(imgMemoryStream)



Can anyone give me an example of how to join the bytes that are sent from the server into a single variable?



What I have tried:

I put it to the client to send a message containing the length of the image, the other client would receive the length and wait for the bytes, and would join in a var, everything went well except for the piece of joining the bytes

解决方案

My solution is:

Sending Img

Dim netStream As NetworkStream
Dim Formatter As IFormatter = New BinaryFormatter()
Formatter.Serialize(netStream, img)



Receive Img

Dim netStream As NetworkStream
Dim Formatter As IFormatter = New BinaryFormatter()
Dim img As Image = Formatter.Deserialize(netStream)



Thank you


这篇关于从字节TCPCLIENT接收图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆