Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 通过套接字加载图像_C#_Sockets - Fatal编程技术网

C# 通过套接字加载图像

C# 通过套接字加载图像,c#,sockets,C#,Sockets,我目前收到以下文本: private void ReceiveCallback(IAsyncResult AR) { try { int received = _clientSocket.EndReceive(AR); //string text = Encoding.ASCII.GetString(_buffer); Array.Resize(ref _buffer, received); //AppendToT

我目前收到以下文本:

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

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

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

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

    // Go ahead and put it in a PictureBox now
}

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

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

    // Go ahead and put it in a PictureBox now
}

谢谢。但现在它说“参数无效”我要写所有代码。在其他问题中谢谢。但现在它说“参数无效”我要写所有代码。在其他问题中