Esempio n. 1
0
        public override void Dispose()
        {
            if (dx11Device != null)
            {
                dx11Device.Dispose();
            }
            if (dx11Factory != null)
            {
                dx11Factory.Dispose();
            }
            if (dx11Output != null)
            {
                dx11Output.Dispose();
            }
            if (dx11DuplicatedOutput != null)
            {
                dx11DuplicatedOutput.Dispose();
            }
            if (dx11ScreenTexture != null)
            {
                dx11ScreenTexture.Dispose();
            }
            if (dx11ScreenResource != null)
            {
                dx11ScreenResource.Dispose();
            }
            if (dx11ScreenSurface != null)
            {
                dx11ScreenSurface.Dispose();
            }

            if (screenShot != null)
            {
                screenShot.Dispose();
            }

            dx11Device           = null;
            dx11Factory          = null;
            dx11Output           = null;
            dx11DuplicatedOutput = null;
            dx11ScreenTexture    = null;
            dx11ScreenResource   = null;
            dx11ScreenSurface    = null;
            screenShot           = null;

            bmpData = null;
            GC.SuppressFinalize(this);
        }
Esempio n. 2
0
 public void Dispose()
 {
     if (duplicatedOutput != null)
     {
         duplicatedOutput.Dispose();
     }
     if (screenTexture != null)
     {
         screenTexture.Dispose();
     }
     if (device != null)
     {
         device.Dispose();
     }
     fluxListenerThread.Abort();
 }
Esempio n. 3
0
        public void setupDX()
        {
            try
            {
                // # of graphics card adapter
                const int numAdapter = 0;

                // # of output device (i.e. monitor)
                const int numOutput = 0;

                //const string outputFileName = "ScreenCapture.png";

                // Create DXGI Factory1
                var factory = new Factory1();
                var adapter = factory.GetAdapter1(numAdapter);

                // Create device from Adapter
                device = new SharpDX.Direct3D11.Device(adapter);


                // Get DXGI.Output
                var output  = adapter.GetOutput(numOutput);
                var output1 = output.QueryInterface <Output1>();

                // Width/Height of desktop to capture
                int width  = ((SharpDX.Rectangle)output.Description.DesktopBounds).Width;
                int height = ((SharpDX.Rectangle)output.Description.DesktopBounds).Height;

                // Create Staging texture CPU-accessible
                var textureDesc = new Texture2DDescription
                {
                    CpuAccessFlags    = CpuAccessFlags.Read,
                    BindFlags         = BindFlags.None,
                    Format            = Format.B8G8R8A8_UNorm,
                    Width             = width,
                    Height            = height,
                    OptionFlags       = ResourceOptionFlags.None,
                    MipLevels         = 1,
                    ArraySize         = 1,
                    SampleDescription = { Count = 1, Quality = 0 },
                    Usage             = ResourceUsage.Staging
                };
                screenTexture = new Texture2D(device, textureDesc);

                // Duplicate the output
                duplicatedOutput = output1.DuplicateOutput(device);
            }
            catch (SharpDXException e)
            {
                if (device != null)
                {
                    device.Dispose();
                }
                if (screenTexture != null)
                {
                    screenTexture.Dispose();
                }
                if (duplicatedOutput != null)
                {
                    duplicatedOutput.Dispose();
                }
                device = null;
                if (e.ResultCode.Code == SharpDX.DXGI.ResultCode.AccessDenied.Result.Code)
                {
                    device = null;
                }
                //else throw e;
            }
            catch (Exception e)
            {
                throw e;
            }


            // TODO: We should cleanp up all allocated COM objects here
        }