title: Get Binary Data From Client and Save it as image
body: <p>I created local server, that should get image files as binary data and save them back as images in hard drive.</p>
  
  <pre><code>Socket mySocket = myListener.AcceptSocket();
  
  #region Connection Check
  if (mySocket.Connected)
  {
          ============
      /* Some Code For Displaying Information*/
          ============
  
      byte[] data = new byte[mySocket.ReceiveBufferSize];
      int i = mySocket.Receive(data, data.Length, 0);
  
      byteArrayToImage(data); 
  
      mySocket.Close();
  }
  </code></pre>
  
  <p><code>byteArrayToImage</code> method Converts byte Array to Image file and saves on hard drive, here's the code</p>
  
  <pre><code>public void byteArrayToImage(Byte[] data)
  {
      MemoryStream ms = new MemoryStream(data);
      Image img = Image.FromStream(ms);
      img.Save(@"C:\MyPersonalwebServer\ImageData\img.png", ImageFormat.Png);
  }
  </code></pre>
  
  <p>but I get ArgumentException here: <code>Image img = Image.FromStream(ms)</code></p>
  
  <p>Here is part of <code>data array</code>: <a href="http://s43.radikal.ru/i101/1403/78/1913ab884790.png" rel="nofollow">http://s43.radikal.ru/i101/1403/78/1913ab884790.png</a></p>
  
  <p>Any ideas how to fix it?
  Thanks in advance.</p>