public static System.Drawing.Image ImageFromTexture(SlimDX.Direct3D11.Texture2D texture, SlimDX.Direct3D11.DeviceContext Context)
 {
     System.Drawing.Image img;
     if (texture.Description.CpuAccessFlags == SlimDX.Direct3D11.CpuAccessFlags.Read)
     {
         DataBox dataRec = Context.MapSubresource(texture, 0, SlimDX.Direct3D11.MapMode.Read, SlimDX.Direct3D11.MapFlags.None);
         byte[] buffer = new byte[dataRec.Data.Length];
         MemoryStream s = new MemoryStream(buffer, true);
         dataRec.Data.CopyTo(s);
         s.Seek(0, SeekOrigin.Begin); //must do this, or error is thrown in next line
         img = System.Drawing.Image.FromStream(s);
         Context.UnmapSubresource(texture, 0);
     }
     else
     {
         img = null;
     }
     return img;
 }