Esempio n. 1
0
        private void StartCapture()
        {
            try
            {
                while (CaptureEnabled)
                {
                    if (!_protoClient.IsConnected())
                    {
                        // Reconnect every 2.5s
                        _protoClient.Init(HyperionServerIp, HyperionServerPort, HyperionMessagePriority);
                        Thread.Sleep(2500);
                        continue;
                    }

                    Surface    s  = _d.CaptureScreen(HyperionWidth, HyperionHeight);
                    DataStream ds = Surface.ToStream(s, ImageFileFormat.Bmp);

                    byte[] buffer = new byte[ds.Length];
                    using (MemoryStream ms = new MemoryStream())
                    {
                        int read;
                        while ((read = ds.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            ms.Write(buffer, 0, read);
                        }

                        byte[] pixelData = ms.ToArray();
                        _protoClient.SendImage(pixelData);

                        Thread.Sleep(CaptureInterval);
                    }

                    ds.Dispose();
                    s.Dispose();
                }
            }
            catch (Exception ex)
            {
                if (NotificationLevel == NotifcationLevels.Info || NotificationLevel == NotifcationLevels.Error)
                {
                    Notifications.Error("Failed to take screenshot." + ex.Message);
                }
            }
        }
Esempio n. 2
0
        private static void StartCapture()
        {
            try
            {
                _d = new DxScreenCapture(Settings.MonitorIndex);

                while (_captureEnabled)
                {
                    if (!ProtoClient.IsConnected())
                    {
                        // Reconnect every 5s (default)
                        ProtoClient.Init(Settings.HyperionServerIp, Settings.HyperionServerPort,
                                         Settings.HyperionMessagePriority);
                        Thread.Sleep(Settings.ReconnectInterval);
                        continue;
                    }

                    var s  = _d.CaptureScreen(Settings.HyperionWidth, Settings.HyperionHeight, _d.MonitorIndex);
                    var dr = s.LockRectangle(LockFlags.None);
                    var ds = dr.Data;
                    var x  = RemoveAlpha(ds);

                    s.UnlockRectangle();
                    s.Dispose();
                    ds.Dispose();

                    ProtoClient.SendImageToServer(x);

                    // Add small delay to reduce cpu usage (200FPS max)
                    Thread.Sleep(Settings.CaptureInterval);
                }

                _d = null;
            }
            catch (Exception ex)
            {
                _captureEnabled = false;
                Notifications.Error("Error occured during capture: " + ex.Message);
            }
        }