我目前正在接收文字:
private void ReceiveCallback(IAsyncResult AR)
{
try
{
int received = _clientSocket.EndReceive(AR);
//string text = Encoding.ASCII.GetString(_buffer);
Array.Resize(ref _buffer, received);
//AppendToTextBox(text);
Array.Resize(ref _buffer, _clientSocket.ReceiveBufferSize);
_clientSocket.BeginReceive(_buffer, 0, _buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), null);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
如何阅读图像而不是文字?
答案 0 :(得分:1)
你可能想等待收到整件事,然后:
using(var ms = new MemoryStream(entireBuffer)) {
var image = Image.FromStream(ms);
// Go ahead and put it in a PictureBox now
}