1

我目前正在接收文本:

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);
    }
}

如何阅读图像而不是文本?

4

1 回答 1

1

您可能希望等待收到整个内容,然后:

using(var ms = new MemoryStream(entireBuffer)) {
    var image = Image.FromStream(ms);

    // Go ahead and put it in a PictureBox now
}
于 2012-12-16T19:05:24.767 回答