void Setup() { InternalOverlay = new Overlay("vrub.desktop." + _screenIndex, "Desktop " + _screenIndex, 2.5f, true, false); InternalOverlay.ToggleInput(true); InternalOverlay.SetTextureSize(_screenObject.Bounds.Width, _screenObject.Bounds.Height); UpdateScreen(); _glTextureId = GL.GenTexture(); ConfigureTexture(); _textureData = new Texture_t(); _textureData.eColorSpace = EColorSpace.Linear; _textureData.eType = ETextureType.OpenGL; _textureData.handle = (IntPtr)_glTextureId; _desktopDuplicator = new DesktopDuplicator(_screenIndex); InternalOverlay.Show(); frameGetter = new Thread(new ThreadStart(GetFrame)); frameGetter.Name = "Desktop " + _screenIndex + " Frame Getter"; frameGetter.Start(); Logger.Debug("[DESKTOP] Display " + _screenIndex + " setup complete"); }
public void CanDecodeDesktopFrame() { var mapJson = File.ReadAllText("./mocks/alignmentmap.json"); var map = JsonConvert.DeserializeObject <IList <int> >(mapJson); using var cts = new CancellationTokenSource(); var desktopDuplicator = new DesktopDuplicator(_mockLogger.Object); var settings = new MatrixSettings() { Map = map, DataFormat = DataMatrixFormat.Raw }; foreach (var desktopFrame in desktopDuplicator.DuplicateDesktop(cts.Token)) { var frame = desktopFrame.DecodeMatrixFrame(settings); if (frame != null) { cts.Cancel(); } } Assert.True(true); }
public static void SetupDuplication() { CanUseGpuAcceleration = false; var config = Config.Load(); if (config.ScreenShareService.UseGpu == false) { return; } var win8Version = new Version(6, 2, 9200, 0); if (Environment.OSVersion.Platform != PlatformID.Win32NT || Environment.OSVersion.Version < win8Version) { Console.WriteLine("Cannot use GPU for Screen Share"); return; } try { _desktopDuplicator = new DesktopDuplicator(0); _nullFrame = true; CanUseGpuAcceleration = true; Console.WriteLine("desktop duplication setup"); } catch (Exception ex) { CanUseGpuAcceleration = false; Console.WriteLine("desktop duplication failed"); Console.WriteLine(ex.Message); } }
public void CanCreateThumbnailFromDesktopFrame() { var mapJson = File.ReadAllText("./mocks/alignmentmap.json"); var map = JsonConvert.DeserializeObject <IList <int> >(mapJson); using var cts = new CancellationTokenSource(); var desktopDuplicator = new DesktopDuplicator(_mockLogger.Object); var settings = new MatrixSettings() { Map = map, DataFormat = DataMatrixFormat.Raw }; foreach (var desktopFrame in desktopDuplicator.DuplicateDesktop(cts.Token)) { var width = (int)Math.Ceiling(desktopFrame.DesktopWidth * 0.15); var height = (int)Math.Ceiling(desktopFrame.DesktopHeight * 0.15); var thumbby = desktopFrame.GetThumbnailImage(width, height); Assert.True(thumbby.Length > 0); cts.Cancel(); } Assert.True(true); }
public void CanGetPointerImageFromDesktopFrame() { var mapJson = File.ReadAllText("./mocks/alignmentmap.json"); var map = JsonConvert.DeserializeObject <IList <int> >(mapJson); using var cts = new CancellationTokenSource(); var desktopDuplicator = new DesktopDuplicator(_mockLogger.Object); var settings = new MatrixSettings() { Map = map, DataFormat = DataMatrixFormat.Raw }; foreach (var desktopFrame in desktopDuplicator.DuplicateDesktop(cts.Token)) { var pointerImage = desktopFrame.GetPointerImage(); //Erm, move the mouse around to get an updated cursor image. if (pointerImage != null) { //Assert.StartsWith("data:image/png;base64,", pointerImage); cts.Cancel(); } } Assert.True(true); }
public Bitmap Capture() { if (_dupl == null) { _dupl = new DesktopDuplicator(_rectangle, _includeCursor, _monitor); } try { return(_dupl.Capture()); } catch { _dupl?.Dispose(); _dupl = new DesktopDuplicator(_rectangle, _includeCursor, _monitor); try { return(_dupl.Capture()); } catch { return(new Bitmap(Width, Height)); } } }
private void InitConnection() { DesktopFrame frame = null; while (true) { try { frame = desktopDuplicator.GetLatestFrame(); break; } catch { desktopDuplicator = new DesktopDuplicator(0); }; } resX = frame.DesktopImage.Width; resY = frame.DesktopImage.Height; if (proc != null) { try { proc.Kill(); } catch { }; } if (audioProc != null) { try { audioProc.Kill(); } catch { }; } audioProc = new Process() { StartInfo = new ProcessStartInfo() { FileName = "ffmpeg.exe", Arguments = string.Format(ffmpeg_audio_args, ip), UseShellExecute = false, RedirectStandardInput = true, RedirectStandardOutput = true, CreateNoWindow = true } }; audioProc.Start(); proc = new Process() { StartInfo = new ProcessStartInfo() { FileName = "ffmpeg.exe", Arguments = string.Format(ffmpeg_args, resX, resY, quality, ip), UseShellExecute = false, RedirectStandardInput = true, RedirectStandardOutput = true, CreateNoWindow = true } }; proc.Start(); }
public DeskDuplImageProvider(Output1 Output, bool IncludeCursor) { var bounds = Output.Description.DesktopBounds; Width = bounds.Right - bounds.Left; Height = bounds.Bottom - bounds.Top; _dupl = new DesktopDuplicator(IncludeCursor, Output); }
void Reinit() { _dupl?.Dispose(); _dupl = new DesktopDuplicator(_rectangle, _includeCursor, _monitor) { Timeout = Timeout }; }
public void GlobalSetup() { _mockLogger = new Mock <ILogger <DesktopDuplicator> >(); _mockLogger .Setup(l => l.Log(It.IsAny <LogLevel>(), It.IsAny <EventId>(), It.IsAny <object>(), It.IsAny <Exception>(), It.IsAny <Func <object, Exception, string> >())) .Callback <LogLevel, EventId, object, Exception, Func <object, Exception, string> >((level, eventId, obj, ex, fn) => { Console.WriteLine($"{level} - {obj} {ex}"); }); _desktopDuplicator = new DesktopDuplicator(_mockLogger.Object); }
internal DeskDuplImageProvider(Adapter Adapter, Output1 Output, Rectangle Rectangle, bool IncludeCursor) { Width = Rectangle.Width; Height = Rectangle.Height; _dupl = new DesktopDuplicator(Rectangle, IncludeCursor, Adapter, Output) { Timeout = Timeout }; }
public DeskDuplImageProvider(Output1 Output, bool IncludeCursor, IPreviewWindow PreviewWindow) { var bounds = Output.Description.DesktopBounds; Width = bounds.Right - bounds.Left; Height = bounds.Bottom - bounds.Top; PointTransform = P => new Point(P.X - bounds.Left, P.Y - bounds.Top); _dupl = new DesktopDuplicator(IncludeCursor, Output, PreviewWindow); }
/* * public CopyScreen(int deviceID) * { * this.desktopDuplicator= new DesktopDuplicator(deviceID); * } * public CopyScreen() * { * this.desktopDuplicator= new DesktopDuplicator(0); * }*/ /// <summary> /// 静态代码块,进行初始化参数 /// </summary> /// static CopyScreen() { try { desktopDuplicator = new DesktopDuplicator(0); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void FormDemo_Shown(object sender, EventArgs e) { while (Visible) { Application.DoEvents(); FormBorderStyle = WindowState == FormWindowState.Maximized ? FormBorderStyle.None : FormBorderStyle.Sizable; DesktopFrame frame; try { frame = _desktopDuplicator.GetLatestFrame(); } catch { _desktopDuplicator = new DesktopDuplicator(0); continue; } if (frame != null) { var update = new Region(); if (frame.CursorBitmap != null) { _cursorImage?.Dispose(); _cursorImage = frame.CursorBitmap; update.Union(new Rectangle(_cursorLocation, _cursorImage.Size)); } if (frame.CursorLocation != new Point()) { update.Union(new Rectangle(_cursorLocation, _cursorImage.Size)); _cursorLocation = frame.CursorLocation; update.Union(new Rectangle(_cursorLocation, _cursorImage.Size)); } if (frame.DesktopImage != null) { _screen?.Dispose(); _screen = frame.DesktopImage; //update.Union(ClientRectangle); foreach (var region in frame.UpdatedRegions) { update.Union(region); } foreach (var region in frame.MovedRegions) { update.Union(region.Destination); } } Invalidate(update, false); } } }
public FormDemo() { InitializeComponent(); try { desktopDuplicator = new DesktopDuplicator(0); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private unsafe void StreamerLoop() { DesktopFrame frame = null; while (true) { if (!started) { running = false; Thread.Sleep(100); continue; } try { frame = desktopDuplicator.GetLatestFrame(); } catch { desktopDuplicator = new DesktopDuplicator(0); continue; } if (frame == null) { continue; } if (resX != frame.DesktopImage.Width || resY != frame.DesktopImage.Height) { InitConnection(); continue; } var bData = frame.DesktopImage.LockBits( new Rectangle(0, 0, frame.DesktopImage.Width, frame.DesktopImage.Height), ImageLockMode.ReadWrite, frame.DesktopImage.PixelFormat); using (var ms = new UnmanagedMemoryStream( (byte *)bData.Scan0.ToPointer(), bData.Width * bData.Height * 4)) { try { proc.StandardInput.BaseStream.Flush(); ms.CopyTo(proc.StandardInput.BaseStream); running = true; } catch { Stop(); } frame.DesktopImage.UnlockBits(bData); } } }
private static DesktopFrame GetScreenPicDxgi() { DesktopFrame frame = null; try { frame = _desktopDuplicator.GetLatestFrame(); } catch (Exception) { _desktopDuplicator = new DesktopDuplicator(0); } return(frame); }
public void CanCaptureDesktop() { using var cts = new CancellationTokenSource(); var desktopDuplicator = new DesktopDuplicator(_mockLogger.Object); foreach (var desktopFrame in desktopDuplicator.DuplicateDesktop(cts.Token)) { Assert.NotNull(desktopFrame); Assert.False(desktopFrame.IsDesktopImageBufferEmpty); cts.Cancel(); } Assert.True(true); }
private static void Initialize() { //SharpDX.Configuration.EnableObjectTracking = true; // DesktopDuplication try { desktopDuplicator = new DesktopDuplicator(0); isInitialized = true; Debug.WriteLine("Desktop Duplication API initialized"); } catch (Exception ex) { MessageBox.Show("An error occurred initializing the screen capture module.\nException: \n" + ex.ToString()); } }
/// <summary> /// 通过DXGI获取桌面图形,只能用于win8以上系统,效果媲美Mirror driver /// 返回值有可能是null(超时会返回0),注意判断使用 /// </summary> /// <returns></returns> public static DesktopFrame getScreenPicDXGI() { DesktopFrame frame = null; try { frame = desktopDuplicator.GetLatestFrame(); } catch (Exception ex) { Console.WriteLine("-------------->>>" + ex.Message); desktopDuplicator = new DesktopDuplicator(0); } return(frame); }
public FormDemo() { InitializeComponent(); try { desktopDuplicator = new DesktopDuplicator(0); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } initializeDetectionManager(); loadDetectionImages(); string dir = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath); testImage = new Bitmap(Image.FromFile(Path.Combine(dir, "AnalysisImages\\Resources\\Test Images\\Test Level Up.png"))); System.Drawing.Rectangle boundsRect = new System.Drawing.Rectangle(0, 0, testImage.Width, testImage.Height); var bitmapData = testImage.LockBits(boundsRect, ImageLockMode.WriteOnly, testImage.PixelFormat); var bitmapPointer = bitmapData.Scan0; Stopwatch performanceWatch = new Stopwatch(); performanceWatch.Start(); unsafe { processDetection((byte *)bitmapPointer.ToPointer(), testImage.Width, testImage.Height); } performanceWatch.Stop(); testImage.UnlockBits(bitmapData); Console.WriteLine("Elapsed milliseconds: {0}", performanceWatch.Elapsed.Ticks / 10000.0); Console.WriteLine("Elapsed fps: {0}", 1000.0 / (performanceWatch.Elapsed.Ticks / 10000.0)); count++; total += performanceWatch.Elapsed.Ticks; Console.WriteLine("Average milliseconds: {0}", total / 10000.0 / count); Console.WriteLine("Average fps: {0}", 1000.0 / (total / 10000.0 / count)); }
public LiveControllerProvider8(NetworkPeer network) : base(network) { try { MirrorDriver = new DesktopDuplicator(0); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } //DesktopChanges = new List<Rectangle>(); //Timer = new Stopwatch(); //MirrorDriver.DesktopChange += new EventHandler<DesktopMirror.DesktopChangeEventArgs>(MirrorDriver_DesktopChange); }
public ConfigForm() { InitializeComponent(); try { desktopDuplicator = new DesktopDuplicator(0, DesktopDuplicator.VSyncLevel.DoubleVsync); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } //if (!performanceMonitor) chart1.Visible = false; if (PerformanceMonitoringIsActive) { PerformanceMonitorEvent += frame_status_update; } }
private void Form1_Shown(object sender, EventArgs e) { using (var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.Default)) { engine.SetVariable("tessedit_char_backlist", "!?@#$%&*()<>_-+=:;'\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"); engine.SetVariable("tessedit_char_whitelist", "/.,0123456789"); engine.SetVariable("classify_bln_numeric_mode", "1"); var rect1 = new Rectangle(55, 785, 130, 50); while (true) { Application.DoEvents(); var elapsed = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; DesktopFrame frame = null; try { frame = desktopDuplicator.GetLatestFrame(); } catch { desktopDuplicator = new DesktopDuplicator(0); continue; } if (frame != null) { Bitmap gauges = this.CropImage(frame.DesktopImage, rect1); using (Image <Gray, Byte> image = new Image <Gray, Byte>(gauges)) using (var tresh = image.ThresholdBinary(new Gray(180), new Gray(255))) { this.pictureBox1.Image = tresh.ToBitmap(); using (var page = engine.Process(tresh.ToBitmap(), new Rect(0, 0, 130, 50))) { this.label1.Text = page.GetText(); this.label2.Text = String.Format("{0}ms", (DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond) - elapsed); } } } } } }
private void TimerDXGI_Tick(object sender, EventArgs e) { var s = Stopwatch.StartNew(); DesktopFrame frame = null; try { frame = desktopDuplicator.GetLatestFrame(); } catch { desktopDuplicator = new DesktopDuplicator(0); } if (frame != null) { this.BackgroundImage = frame.DesktopImage; } fps++; tim += s.ElapsedMilliseconds; }
public override void RegisterMessageHandlers() { Network.RegisterMessageHandler<RequestScreenshotMessage>(OnRequestScreenshotMessageReceived); while (true) { Application.DoEvents(); try { frame = MirrorDriver.GetLatestFrame(); } catch { MirrorDriver = new DesktopDuplicator(0); continue; } if (frame != null) { //LabelCursor.Location = frame.CursorLocation; //LabelCursor.Visible = frame.CursorVisible; //Debug.WriteLine("--------------------------------------------------------"); //foreach (var moved in frame.MovedRegions) //{ // Debug.WriteLine(String.Format("Moved: {0} -> {1}", moved.Source, moved.Destination)); // MovedRegion.Location = moved.Destination.Location; // MovedRegion.Size = moved.Destination.Size; //} //foreach (var updated in frame.UpdatedRegions) //{ // Debug.WriteLine(String.Format("Updated: {0}", updated.ToString())); // UpdatedRegion.Location = updated.Location; // UpdatedRegion.Size = updated.Size; //} //this.BackgroundImage = frame.DesktopImage; } } }
private DesktopFrame GetNextFrame() { if (_desktopDuplicator == null) { _desktopDuplicator = new DesktopDuplicator(0, 0); } try { var frame = _desktopDuplicator.GetLatestFrame(); return(frame); } catch (Exception ex) { _log.Error(ex, "GetNextFrame() failed."); _desktopDuplicator?.Dispose(); _desktopDuplicator = null; throw; } }
private void FormDemo_Shown(object sender, EventArgs e) { while (true) { Application.DoEvents(); DesktopFrame frame = null; try { frame = desktopDuplicator.GetLatestFrame(); } catch { desktopDuplicator = new DesktopDuplicator(0); continue; } if (frame != null) { LabelCursor.Location = frame.CursorLocation; LabelCursor.Visible = frame.CursorVisible; //Debug.WriteLine("--------------------------------------------------------"); //foreach (var moved in frame.MovedRegions) //{ // Debug.WriteLine(String.Format("Moved: {0} -> {1}", moved.Source, moved.Destination)); // MovedRegion.Location = moved.Destination.Location; // MovedRegion.Size = moved.Destination.Size; //} //foreach (var updated in frame.UpdatedRegions) //{ // Debug.WriteLine(String.Format("Updated: {0}", updated.ToString())); // UpdatedRegion.Location = updated.Location; // UpdatedRegion.Size = updated.Size; //} this.BackgroundImage = frame.DesktopImage; fps++; } } }
public Bitmap Capture() { try { return(_dupl.Capture()); } catch { try { _dupl?.Dispose(); _dupl = new DesktopDuplicator(WindowProvider.DesktopRectangle, _includeCursor, _monitor); return(_dupl.Capture()); } catch { return(new Bitmap(Width, Height)); } } }
/// <summary> /// Gets the next screen frame. DISPOSE of the bitmap when you're done using it! /// </summary> /// <returns></returns> public static Bitmap GetNextFrame() { if (!isInitialized) { Initialize(); } try { DesktopFrame frame = desktopDuplicator.GetLatestFrame(); if (frame != null) { Bitmap frameBitmap = frame.DesktopImage; return(frameBitmap); } } catch (Exception) { desktopDuplicator.Dispose(); desktopDuplicator = new DesktopDuplicator(0); Debug.WriteLine("Exception in DesktopDuplication API occurred. User probably switched windows"); } return(null); }
public FormDemo() { InitializeComponent(); desktopDuplicator = new DesktopDuplicator(0,0); }