/// <summary> /// Duplicates the output of the specified monitor on the specified graphics adapter. /// </summary> /// <param name="whichGraphicsCardAdapter">The adapter which contains the desired outputs.</param> /// <param name="whichOutputDevice">The output device to duplicate (i.e. monitor). Begins with zero, which seems to correspond to the primary monitor.</param> public DesktopDuplicator(int whichGraphicsCardAdapter, int whichOutputDevice, VSyncLevel vSync) { this.vSync = vSync; this.mWhichOutputDevice = whichOutputDevice; Adapter1 adapter; try { adapter = new Factory1().GetAdapter1(whichGraphicsCardAdapter); } catch (SharpDXException) { throw new DesktopDuplicationException("Could not find the specified graphics card adapter."); } this.mDevice = new Device(adapter, DeviceCreationFlags.SingleThreaded | DeviceCreationFlags.PreventAlteringLayerSettingsFromRegistry); Output output; try { output = adapter.GetOutput(whichOutputDevice); } catch (SharpDXException) { throw new DesktopDuplicationException("Could not find the specified output device."); } outputStream = output.QueryInterface <Output1>(); this.mOutputDescription = output.Description; this.mTextureDescription = new Texture2DDescription() { CpuAccessFlags = CpuAccessFlags.Read, BindFlags = BindFlags.None, Format = Format.B8G8R8A8_UNorm, Width = this.mOutputDescription.DesktopBounds.Right, Height = this.mOutputDescription.DesktopBounds.Bottom, OptionFlags = ResourceOptionFlags.None, MipLevels = 1, ArraySize = 1, SampleDescription = { Count = 1, Quality = 0 }, Usage = ResourceUsage.Staging }; try { this.mDeskDuplication = outputStream.DuplicateOutput(mDevice); } catch (SharpDXException err) { if (err.ResultCode.Code == SharpDX.DXGI.ResultCode.NotCurrentlyAvailable.Result.Code) { throw new DesktopDuplicationException("There is already the maximum number of applications using the Desktop Duplication API running, please close one of the applications and try again."); } } }
/// <summary> /// Duplicates the output of the specified monitor. /// </summary> /// <param name="whichMonitor">The output device to duplicate (i.e. monitor). Begins with zero, which seems to correspond to the primary monitor.</param> public DesktopDuplicator(int whichMonitor, VSyncLevel vSync) : this(0, whichMonitor, vSync) { }