SlimDX 当游戏窗口全模式抛出错误

SlimDX When Game WindowFullmode Throw Error

DxScreenCapture.cs

 public class DxScreenCapture
    {
        Device d;

        public DxScreenCapture()
        {
            PresentParameters present_params = new PresentParameters();
            present_params.Windowed = true;
            present_params.SwapEffect = SwapEffect.Discard;
            d = new Device(new Direct3D(), 0, DeviceType.Hardware, IntPtr.Zero, CreateFlags.SoftwareVertexProcessing, present_params);
        }

        public Surface CaptureScreen()
        {
            Surface s = Surface.CreateOffscreenPlain(d, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, Format.A8R8G8B8, Pool.Scratch);
            d.GetFrontBufferData(0, s);
            return s;
        }
    }

捕获图像并序列化发送服务器

 using (Surface s = cap.CaptureScreen())
            {

                BinaryFormatter bf = new BinaryFormatter();
               Bitmap bitmap = new Bitmap(SlimDX.Direct3D9.Surface.ToStream(s, SlimDX.Direct3D9.ImageFileFormat.Bmp));

                ns = client.GetStream();
                bf.Serialize(ns, bitmap); // ns = NetworkStream
            }

当游戏不是 运行 状态时效果很好。 但游戏 运行 处于完全 window 模式 抛出异常

SlimDX.Direct3D9.Direct3D9Exception

这是内部例外:

D3DERR_INVALIDCALL: Invalid call (-2005530516)

Excpetion Details

也许 this answer 也适合您的问题

My guess is that your graphics card probably doesn't support a 1x1 backbuffer.

Take a look at the output from the debug runtimes. Whenever you get an InvalidCall chances are good that there's some sort of diagnostic information there indicating what you did wrong.