Exemple #1
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            //build various controllers and renderers
            renderController = new RenderController(this.Handle);
            //call create resources if needed
            frameGrabber = new FrameGrabber(this.ClientSize.Width, this.ClientSize.Height);

            //other stuff
            this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
            currentSize = this.ClientSize;
        }
Exemple #2
0
        public void Render(RenderController renderController)
        {
            var rc_context = renderController.GetDeviceContext();

            try
            {
                SharpDX.DXGI.Resource           screenResource;
                OutputDuplicateFrameInformation frameInfo;

                duplicatedOutput.AcquireNextFrame(1000, out frameInfo, out screenResource);

                //Console.WriteLine(frameInfo.AccumulatedFrames);
                if (screenResource != null)
                {
                    using (var screenTexture2D = screenResource.QueryInterface <Texture2D>())
                    {
                        device.ImmediateContext.CopySubresourceRegion(
                            screenTexture2D,
                            0,
                            new ResourceRegion(_CaptureLeft, _CaptureTop, 0, _CaptureRight, _CaptureBottom, 1),
                            captureTexture,
                            0
                            );
                    }
                    var mapSource = device.ImmediateContext.MapSubresource(captureTexture, 0, MapMode.Read, MapFlags.None);
                    var outbmp    = new SharpDX.Direct2D1.Bitmap(
                        rc_context,
                        new Size2(_CaptureWidth, _CaptureHeight),
                        new SharpDX.Direct2D1.BitmapProperties(
                            new SharpDX.Direct2D1.PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm,
                                                              SharpDX.Direct2D1.AlphaMode.Ignore)
                            )
                        );
                    outbmp.CopyFromMemory(mapSource.DataPointer, mapSource.RowPitch);
                    device.ImmediateContext.UnmapSubresource(captureTexture, 0);

                    rc_context.BeginDraw();
                    rc_context.DrawBitmap(outbmp, 1.0f, SharpDX.Direct2D1.BitmapInterpolationMode.Linear);
                    rc_context.EndDraw();

                    screenResource.Dispose();
                    duplicatedOutput.ReleaseFrame();
                }
            }
            catch (SharpDXException e)
            {
                if (e.ResultCode.Code != SharpDX.DXGI.ResultCode.WaitTimeout.Result.Code)
                {
                    Console.WriteLine(e.Message);
                    Console.ReadLine();
                }
            }
        }