title: Efficient way to send images via WCF?
body: <p>I am learning WCF, LINQ and a few other technologies by writing, from scratch, a custom remote control application like VNC.  I am creating it with three main goals in mind:</p>
  
  <ol>
  <li>The server will provide 'remote control' on an application level (i.e. seamless windows) instead of full desktop access. </li>
  <li>The client can select any number of applications that are running on the server and receive a stream of images of each of them.</li>
  <li>A client can connect to more than one server simultaneously.</li>
  </ol>
  
  <p>Right now I am using WCF to send an array of Bytes that represents the window being sent:</p>
  
  <pre><code>using (var ms = new MemoryStream()) {
      window.GetBitmap().Save(ms, ImageFormat.Jpeg);
      frame.Snapshot = ms.ToArray();
  }
  </code></pre>
  
  <p>GetBitmap implementation:</p>
  
  <pre><code>var wRectangle = GetRectangle();
  var image = new Bitmap(wRectangle.Width, wRectangle.Height);
  var gfx = Graphics.FromImage(image);
  
  gfx.CopyFromScreen(wRectangle.Left, wRectangle.Top, 0, 0, wRectangle.Size, CopyPixelOperation.SourceCopy);
  
  return image;
  </code></pre>
  
  <p>It is then sent via WCF (TCPBinding and it will always be over LAN) to the client and reconstructed in a blank windows form with no border like this:</p>
  
  <pre><code>using (var ms = new MemoryStream(_currentFrame.Snapshot))
  {
      BackgroundImage = Image.FromStream(ms);
  }
  </code></pre>
  
  <p>I would like to make this process as efficient as possible in both CPU and memory usage with bandwidth coming in third place.  I am aiming to have the client connect to 5+ servers with 10+ applications per server.</p>
  
  <p>Is my existing method the best approach (while continuing to use these technologies) and is there anything I can do to improve it?</p>
  
  <p>Ideas that I am looking into (but I have no experience with):</p>
  
  <ul>
  <li>Using an open source graphics library to capture and save the images instead of .Net solution.</li>
  <li>Saving as PNG or another image type rather than JPG.</li>
  <li>Send image deltas instead of a full image every time.</li>
  <li>Try and 'record' the windows and create a compressed video stream instead of picture snapshots (mpeg?).</li>
  </ul>