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;
}
}
Capture Image and Serialize to Send Server
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
}
When Game Not Running state Works Great. but Game running on full window mode Throws Excpetion
SlimDX.Direct3D9.Direct3D9Exception
And this is the Inner exception:
D3DERR_INVALIDCALL: Invalid call (-2005530516)
Maybe this answer fits your problem as well
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.