public static ScreenCapture Create(VideoCaptureType type, object[] args = null)
        {
            ScreenCapture capture = null;

            if (type == VideoCaptureType.GDI || type == VideoCaptureType.GDILayered)
            {
                var gdiCapt = new GDICapture(args);
                gdiCapt.CaptureAllLayers = (type == VideoCaptureType.GDILayered);

                capture = gdiCapt;
            }
            else if (type == VideoCaptureType.Direct3D9)
            {
                capture = new Direct3D9Capture(args);
            }
            else if (type == VideoCaptureType.GDIPlus)
            {
                capture = new GDIPlusCapture();
            }
            else if (type == VideoCaptureType.Datapath)
            {
                capture = new DatapathDesktopCapture();
            }
            else if (type == VideoCaptureType.DXGIDeskDupl)
            {
                capture = new DXGIDesktopDuplicationCapture(args);
            }

            return(capture);
        }
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                if (httpScreenStreamer == null)
                {
                    httpScreenStreamer = new HttpScreenStreamer();

                    httpScreenStreamer.StreamerStarted += HttpScreenStreamer_StreamerStarted;
                    httpScreenStreamer.StreamerStopped += HttpScreenStreamer_StreamerStopped;
                }

                var srcRect     = HttpGetCurrentScreen(); //currentScreen.Bounds;
                var _destWidth  = (int)httpDestWidthNumeric.Value;
                var _destHeight = (int)httpDestHeightNumeric.Value;

                var destSize = new Size(_destWidth, _destHeight);
                VideoCaptureType captureType = (VideoCaptureType)captureTypesComboBox.SelectedItem;


                HttpScreenStreamerArgs args = new HttpScreenStreamerArgs
                {
                    Addres        = httpAddrTextBox.Text,
                    Port          = (int)httpPortNumeric.Value,
                    CaptureRegion = srcRect,
                    Resolution    = destSize,

                    Fps          = (int)httpFpsNumeric.Value,
                    CaptureTypes = captureType,
                    CaptureMouse = true,
                    //UseDesktopDuplApi = (captureType == VideoCaptureType.DXGIDeskDupl),
                };

                httpScreenStreamer.Setup(args);

                httpScreenStreamer.Start();

                this.Cursor = Cursors.WaitCursor;

                this.Enabled = false;
            }
            catch (Exception ex)
            {
                logger.Error(ex);

                MessageBox.Show(ex.ToString());
            }
        }
        // private Screen currentScreen = null;


        private void httpStartButton_Click(object sender, EventArgs e)
        {
            //currentScreen = HttpGetCurrentScreen();

            var srcRect = HttpGetCurrentScreen(); //currentScreen.Bounds;
            //var srcRect = currentScreen.Bounds;

            var _destWidth  = (int)httpDestWidthNumeric.Value;
            var _destHeight = (int)httpDestHeightNumeric.Value;

            var destSize = new Size(_destWidth, _destHeight);

            var ratio      = srcRect.Width / (double)srcRect.Height;
            int destWidth  = destSize.Width;
            int destHeight = (int)(destWidth / ratio);

            if (ratio < 1)
            {
                destHeight = destSize.Height;
                destWidth  = (int)(destHeight * ratio);
            }

            destSize = new Size(destWidth, destHeight);


            var fps = httpFpsNumeric.Value;

            var addr = httpAddrTextBox.Text;
            var port = (int)httpPortNumeric.Value;

            VideoCaptureType captureType = (VideoCaptureType)captureTypesComboBox.SelectedItem;

            httpScreenSource = new ScreenSource();
            ScreenCaptureDevice captureParams = new ScreenCaptureDevice
            {
                CaptureRegion = srcRect,
                Resolution    = destSize,
            };

            captureParams.Properties.CaptureType = captureType;//CaptureType.DXGIDeskDupl,

            captureParams.Properties.Fps          = (int)fps;
            captureParams.Properties.CaptureMouse = true;
            captureParams.Properties.AspectRatio  = true;
            captureParams.Properties.UseHardware  = false;

            if (captureType == VideoCaptureType.GDI || captureType == VideoCaptureType.GDIPlus)
            {// масштабируем на энкодере
                captureParams.Resolution = new Size(srcRect.Width, srcRect.Height);
            }

            httpScreenSource.Setup(captureParams);


            httpStreamer = new VideoHttpStreamer(httpScreenSource);

            NetworkSettings networkParams = new NetworkSettings
            {
                RemoteAddr = addr,
                RemotePort = port,
            };


            VideoEncoderSettings encodingParams = new VideoEncoderSettings
            {
                Width  = destSize.Width,  // options.Width,
                Height = destSize.Height, // options.Height,
                //Resolution = destSize,
                FrameRate = new MediaRatio((int)fps, 1),
                EncoderId = "mjpeg",
            };

            httpStreamer.Setup(encodingParams, networkParams);


            httpStreamer.Start();
            httpScreenSource.Start();


            statisticForm.Location = srcRect.Location;
            // statisticForm.Start();
        }