void CaptureScreenShot() { Bitmap bmp = null; var selectedVideoSource = VideoViewModel.SelectedVideoSource; var includeCursor = Settings.IncludeCursor; switch (VideoViewModel.SelectedVideoSourceKind) { case VideoSourceKind.Window: var hWnd = (selectedVideoSource as WindowItem)?.Window ?? Window.DesktopWindow; bmp = ScreenShotWindow(hWnd); break; case VideoSourceKind.Screen: bmp = (selectedVideoSource as ScreenItem)?.Capture(includeCursor); break; case VideoSourceKind.Region: bmp = ScreenShot.Capture(RegionSelector.Instance.Rectangle, includeCursor); break; } SaveScreenShot(bmp); }
public void StartStream(int width, int height, PixelFormat pf) { StreamTask = Task.Run(() => { while (this.StreamSocket.Connected) { try { //using (Bitmap bmp = PrintScreen(width, height, pf)) using (Bitmap bmp = ScreenShot.Capture(true)) { MemoryStream ms = new MemoryStream(); bmp.Save(ms, ImageFormat.Jpeg); SendImage(ms.ToArray()); ms.Dispose(); } //Manage the FPS of the stream System.Threading.Thread.Sleep(1000 / FPS); } catch (Exception e) { } } }); }
public static async Task <ImageSource> GetBackground() { var vm = ServiceProvider.Get <VideoSourcesViewModel>(); IBitmapImage bmp; switch (vm.SelectedVideoSourceKind?.Source) { case NoVideoItem _: bmp = ScreenShot.Capture(); break; default: var screenShotModel = ServiceProvider.Get <ScreenShotModel>(); bmp = await screenShotModel.GetScreenShot(vm.SelectedVideoSourceKind, true); break; } if (bmp == null) { bmp = ScreenShot.Capture(); } using (bmp) { var stream = new MemoryStream(); bmp.Save(stream, ImageFormats.Png); stream.Seek(0, SeekOrigin.Begin); var decoder = new PngBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.Default); return(decoder.Frames[0]); } }
public Bitmap ScreenShotWindow(IWindow hWnd) { _systemTray.HideNotification(); if (hWnd.Handle == Window.DesktopWindow.Handle) { return(ScreenShot.Capture(Settings.IncludeCursor).Transform(Settings.ScreenShots)); } var bmp = ScreenShot.CaptureTransparent(hWnd, Settings.IncludeCursor, Settings.ScreenShots.Resize, Settings.ScreenShots.ResizeWidth, Settings.ScreenShots.ResizeHeight); // Capture without Transparency if (bmp == null) { try { return(ScreenShot.Capture(hWnd, Settings.IncludeCursor)?.Transform(Settings.ScreenShots)); } catch { return(null); } } return(bmp.Transform(Settings.ScreenShots, true)); }
public IBitmapImage ScreenShotWindow(IWindow Window) { _systemTray.HideNotification(); if (Window.Handle == _platformServices.DesktopWindow.Handle) { return(ScreenShot.Capture(_settings.IncludeCursor)); } try { IBitmapImage bmp = null; if (_settings.ScreenShots.WindowShotTransparent) { bmp = ScreenShot.CaptureTransparent(Window, _settings.IncludeCursor); } // Capture without Transparency return(bmp ?? ScreenShot.Capture(Window.Rectangle, _settings.IncludeCursor)); } catch { return(null); } }
public IBitmapImage Capture(bool IncludeCursor) { var cursorPos = _platformServices.CursorPosition; var screenBounds = _platformServices.DesktopRectangle; var w = _settings.AroundMouseWidth; var h = _settings.AroundMouseHeight; var region = new Rectangle(cursorPos.X - w / 2, cursorPos.Y - h / 2, w, h); if (region.Right > screenBounds.Right) { region.X = screenBounds.Right - w; } if (region.Bottom > screenBounds.Bottom) { region.Y = screenBounds.Bottom - h; } if (region.X < screenBounds.X) { region.X = screenBounds.X; } if (region.Y < screenBounds.Y) { region.Y = screenBounds.Y; } return(ScreenShot.Capture(region, IncludeCursor)); }
public Bitmap ScreenShotWindow(IWindow Window) { _systemTray.HideNotification(); if (Window.Handle == Screna.Window.DesktopWindow.Handle) { return(ScreenShot.Capture(Settings.IncludeCursor)); } try { Bitmap bmp = null; if (Settings.ScreenShots.WindowShotTransparent) { bmp = ScreenShot.CaptureTransparent(Window, Settings.IncludeCursor); } // Capture without Transparency return(bmp ?? ScreenShot.Capture(Window, Settings.IncludeCursor)); } catch { return(null); } }
async void UpdateBackground() { var vm = ServiceProvider.Get <VideoSourcesViewModel>(); Bitmap bmp; switch (vm.SelectedVideoSourceKind?.Source) { case FullScreenItem _: case NoVideoItem _: bmp = ScreenShot.Capture(); break; default: var screenShotModel = ServiceProvider.Get <ScreenShotModel>(); bmp = await screenShotModel.GetScreenShot(); break; } using (bmp) { var stream = new MemoryStream(); bmp.Save(stream, ImageFormat.Png); stream.Seek(0, SeekOrigin.Begin); var decoder = new PngBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.Default); Img.Source = decoder.Frames[0]; } }
public void teardown() { var status = TestContext.CurrentContext.Result.Outcome.Status; var stacktrace = string.IsNullOrEmpty(TestContext.CurrentContext.Result.StackTrace) ? "" : string.Format("{0}", TestContext.CurrentContext.Result.Message); Status logstatus; var errorMessage = TestContext.CurrentContext.Result.Message; switch (status) { case TestStatus.Failed: logstatus = Status.Fail; string screenShotPath = ScreenShot.Capture(driver, browserstr); _test.Log(Status.Info, stacktrace + errorMessage); _test.Log(Status.Info, "Snapshot below: " + _test.AddScreenCaptureFromPath(screenShotPath)); screenShotPath = screenShotPath.Replace(@"C:\Users\admin\Desktop\Automation\Regression Scripts\18.2\", @"Z:\"); _test.Log(Status.Info, "MailSnapshot below: " + _test.AddScreenCaptureFromPath(screenShotPath)); if (driver.Title == "Object reference not set to an instance of an object.") { driver.Navigate_to_TrainingHome(); Driver.focusParentWindow(); CommonSection.Avatar.Logout(); LoginPage.LoginClick(); LoginPage.LoginAs("siteadmin").WithPassword("password").Login(); } break; case TestStatus.Inconclusive: logstatus = Status.Warning; break; case TestStatus.Skipped: logstatus = Status.Skip; break; default: logstatus = Status.Pass; break; } _test.Log(logstatus, "Test ended with " + logstatus + stacktrace); // _extent.Flush(); if (Meridian_Common.islog == true) { driver.LogoutUser(ObjectRepository.LogoutHoverLink, ObjectRepository.HoverMainLink); } else { driver.Navigate_to_TrainingHome(); // TrainingHomeobj.lnk_TrainingManagement_click(By.XPath("//a[contains(.,'Administer')]"), By.XPath("//a[contains(.,'Training Management')]")); //if (!driver.GetElement(By.Id("lbUserView")).Displayed) //{ // driver.Navigate().Refresh(); //} // driver.Navigate().Refresh(); } }
public override IBitmapImage Capture(bool IncludeCursor) { if (Source is WindowItem windowItem) { return(ScreenShot.Capture(windowItem.Window.Rectangle, IncludeCursor)); } return(null); }
public override IBitmapImage Capture(bool IncludeCursor) { if (Source is ScreenItem screenItem) { return(ScreenShot.Capture(screenItem.Screen.Rectangle, IncludeCursor)); } return(null); }
public async Task ScreenshotWindow() { var window = _sourcePicker.PickWindow(); if (window != null) { var img = ScreenShot.Capture(window.Rectangle); await SaveScreenShot(img); } }
private void BtnScreenshot_MouseDown(object sender, MouseEventArgs e) { if (e.Clicks > 1) { // 双击截图 ScreenShot.Capture(); return; } // 直接按住拖动窗口 MouseDownEventHandler(sender, e); }
public async Task ScreenshotScreen() { var screen = _sourcePicker.PickScreen(); if (screen != null) { var img = ScreenShot.Capture(screen.Rectangle); await SaveScreenShot(img); } }
public async void CaptureScreenShot(string FileName = null) { _systemTray.HideNotification(); Bitmap bmp = null; var selectedVideoSource = VideoViewModel.SelectedVideoSource; var includeCursor = Settings.IncludeCursor; switch (VideoViewModel.SelectedVideoSourceKind) { case WindowSourceProvider _: var hWnd = (selectedVideoSource as WindowItem)?.Window ?? Window.DesktopWindow; bmp = ScreenShotWindow(hWnd); break; case DeskDuplSourceProvider _: case ScreenSourceProvider _: if (selectedVideoSource is FullScreenItem) { var hide = _mainWindow.IsVisible && Settings.UI.HideOnFullScreenShot; if (hide) { _mainWindow.IsVisible = false; // Ensure that the Window is hidden await Task.Delay(300); } bmp = ScreenShot.Capture(includeCursor); if (hide) { _mainWindow.IsVisible = true; } } else if (selectedVideoSource is ScreenItem screen) { bmp = screen.Capture(includeCursor); } bmp = bmp?.Transform(Settings.ScreenShots); break; case RegionSourceProvider _: bmp = ScreenShot.Capture(_regionProvider.SelectedRegion, includeCursor); bmp = bmp.Transform(Settings.ScreenShots); break; } SaveScreenShot(bmp, FileName); }
public async Task ScreenshotRegion() { var region = _sourcePicker.PickRegion(); if (region == null) { return; } await SaveScreenShot(ScreenShot.Capture(region.Value)); }
private void ButtonPick_OnMouseMove(object sender, MouseEventArgs e) { if (_mDown) { Point pos = PointToScreen(e.GetPosition(null)); Bitmap cap = ScreenShot.Capture(new Rectangle((int)pos.X, (int)pos.Y, 1, 1)); System.Drawing.Color capCol = cap.GetPixel(0, 0); Color = Color.FromRgb(capCol.R, capCol.G, capCol.B, capCol.A); } //throw new NotImplementedException(); }
//[TearDown] public void stoptest() { var status = TestContext.CurrentContext.Result.Outcome.Status; var stacktrace = string.IsNullOrEmpty(TestContext.CurrentContext.Result.StackTrace) ? "" : string.Format("{0}", TestContext.CurrentContext.Result.StackTrace); var errorMessage = TestContext.CurrentContext.Result.Message; Status logstatus; switch (status) { case TestStatus.Failed: logstatus = Status.Fail; string screenShotPath = ScreenShot.Capture(driver, browserstr); _test.Log(Status.Info, "Assertion has been Failed, Please Take a Look to Below Screenshot and StackTrace"); _test.Log(Status.Info, stacktrace + errorMessage); _test.Log(Status.Info, "Snapshot below: " + _test.AddScreenCaptureFromPath(screenShotPath)); screenShotPath = screenShotPath.Replace(@"C:\Users\admin\Desktop\Automation\Regression Scripts\18.2\", @"Z:\"); _test.Log(Status.Info, "MailSnapshot below: " + _test.AddScreenCaptureFromPath(screenShotPath)); break; case TestStatus.Inconclusive: logstatus = Status.Warning; break; case TestStatus.Skipped: logstatus = Status.Skip; break; default: logstatus = Status.Pass; break; } _test.Log(logstatus, "Test ended with " + logstatus + stacktrace); // _extent.Flush(); if (Meridian_Common.islog == true) { driver.LogoutUser(ObjectRepository.LogoutHoverLink, ObjectRepository.HoverMainLink); } else { CommonSection.Learn.Home(); // Driver.Instance.Navigate_to_TrainingHome(); // TrainingHomeobj.lnk_TrainingManagement_click(By.XPath("//a[contains(.,'Administer')]"), By.XPath("//a[contains(.,'Training Management')]")); //if (!driver.GetElement(By.Id("lbUserView")).Displayed) //{ // driver.Navigate().Refresh(); //} // driver.Navigate().Refresh(); } }
public Bitmap Capture() { var bmp = ScreenShot.Capture(Rectangle); using (var g = Graphics.FromImage(bmp)) foreach (var overlay in _overlays) { overlay.Draw(g, Rectangle.Location); } return(bmp); }
void UpdateBackground() { using (var bmp = ScreenShot.Capture()) { var stream = new MemoryStream(); bmp.Save(stream, ImageFormat.Png); stream.Seek(0, SeekOrigin.Begin); var decoder = new PngBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.Default); Background = new ImageBrush(decoder.Frames[0]); } }
public Bitmap ScreenShotWindow(Window hWnd) { if (hWnd == Window.DesktopWindow) { return(ScreenShot.Capture(Settings.IncludeCursor)); } else { var bmp = ScreenShot.CaptureTransparent(hWnd, Settings.IncludeCursor, Settings.ScreenShotDoResize, Settings.ScreenShotResizeWidth, Settings.ScreenShotResizeHeight); // Capture without Transparency if (bmp == null) { bmp = ScreenShot.Capture(hWnd, Settings.IncludeCursor); } return(bmp); } }
void SendScreenShot() { string screenshot = Convert.ToBase64String(ScreenShot.Capture(screenShotCamera)); int chunks = screenshot.Length / screenShotChunkSize; int reminder = screenshot.Length % screenShotChunkSize; queue_watchers_data.Enqueue(new EnvironmentMessage { type = EnvironmentMessage.Type.ScreenShotStart }); for (int i = 0; i < chunks; ++i) { SendScreenShotChunk(screenshot, i, screenShotChunkSize); } if (reminder > 0) { SendScreenShotChunk(screenshot, chunks, reminder); } queue_watchers_data.Enqueue(new EnvironmentMessage { type = EnvironmentMessage.Type.ScreenShotEnd }); }
public ScreenPickerViewModel(IScreen Screen, double Scale) { this.Screen = Screen; using var bmp = ScreenShot.Capture(Screen.Rectangle); var stream = new MemoryStream(); bmp.Save(stream, ImageFormats.Png); stream.Seek(0, SeekOrigin.Begin); var decoder = new PngBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.Default); Image = new ImageBrush(decoder.Frames[0]); Left = (Screen.Rectangle.Left / Dpi.X - SystemParameters.VirtualScreenLeft) * Scale; Top = (Screen.Rectangle.Top / Dpi.Y - SystemParameters.VirtualScreenTop) * Scale; Width = Screen.Rectangle.Width / Dpi.X * Scale; Height = Screen.Rectangle.Height / Dpi.Y * Scale; }
public override IBitmapImage Capture(bool IncludeCursor) { return(ScreenShot.Capture(_regionProvider.SelectedRegion, IncludeCursor)); }
void CaptureScreenShot() { if (!Directory.Exists(OutPath)) { Directory.CreateDirectory(OutPath); } string fileName = null; var imgFmt = ScreenShotViewModel.SelectedImageFormat; var extension = imgFmt.Equals(ImageFormat.Icon) ? "ico" : imgFmt.Equals(ImageFormat.Jpeg) ? "jpg" : imgFmt.ToString().ToLower(); var saveToClipboard = ScreenShotViewModel.SelectedSaveTo == "Clipboard"; if (!saveToClipboard) { fileName = Path.Combine(OutPath, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + "." + extension); } Bitmap bmp = null; var selectedVideoSource = VideoViewModel.SelectedVideoSource; var includeCursor = OthersViewModel.Cursor; switch (VideoViewModel.SelectedVideoSourceKind) { case VideoSourceKind.Window: var hWnd = (selectedVideoSource as WindowVSLI)?.Window ?? Window.DesktopWindow; if (hWnd == Window.DesktopWindow) { bmp = ScreenShot.Capture(includeCursor); } else if (hWnd == RegionSelector.Instance.Window) { bmp = ScreenShot.Capture(RegionSelector.Instance.Rectangle, includeCursor); } else { bmp = ScreenShot.CaptureTransparent(hWnd, includeCursor, ScreenShotViewModel.DoResize, ScreenShotViewModel.ResizeWidth, ScreenShotViewModel.ResizeHeight); } break; case VideoSourceKind.Screen: bmp = (selectedVideoSource as ScreenVSLI)?.Capture(includeCursor); break; } // Save to Disk or Clipboard if (bmp != null) { if (saveToClipboard) { bmp.WriteToClipboard(imgFmt.Equals(ImageFormat.Png)); Status = "Image Saved to Clipboard"; } else { try { bmp.Save(fileName, imgFmt); Status = "Image Saved to Disk"; RecentViewModel.Add(fileName, RecentItemType.Image); } catch (Exception E) { Status = "Not Saved. " + E.Message; } } } else { Status = "Not Saved - Image taken was Empty"; } }
void CaptureScreenShot(object sender = null, RoutedEventArgs e = null) { if (!Directory.Exists(OutPath.Text)) { Directory.CreateDirectory(OutPath.Text); } string FileName = null; ImageFormat ImgFmt = ScreenShotSettings.SelectedImageFormat; string Extension = ImgFmt == ImageFormat.Icon ? "ico" : ImgFmt == ImageFormat.Jpeg ? "jpg" : ImgFmt.ToString().ToLower(); bool SaveToClipboard = ScreenShotSettings.SaveToClipboard; if (!SaveToClipboard) { FileName = Path.Combine(OutPath.Text, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + "." + Extension); } Bitmap BMP = null; var SelectedVideoSourceKind = VideoSettings.SelectedVideoSourceKind; var SelectedVideoSource = VideoSettings.SelectedVideoSource; var IncludeCursor = Properties.Settings.Default.IncludeCursor; if (SelectedVideoSourceKind == VideoSourceKind.Window) { IntPtr hWnd = (SelectedVideoSource as WindowVSLI).Handle; if (hWnd == WindowProvider.DesktopHandle) { BMP = ScreenShot.Capture(IncludeCursor); } else if (hWnd == RegionSelector.Instance.Handle) { BMP = ScreenShot.Capture(RegionSelector.Instance.Rectangle, IncludeCursor); } else { BMP = ScreenShot.CaptureTransparent(hWnd, IncludeCursor, ScreenShotSettings.DoResize, ScreenShotSettings.ResizeWidth, ScreenShotSettings.ResizeHeight); } } else if (SelectedVideoSourceKind == VideoSourceKind.Screen) { BMP = (SelectedVideoSource as ScreenVSLI).Capture(IncludeCursor); } // Save to Disk or Clipboard if (BMP != null) { if (SaveToClipboard) { BMP.WriteToClipboard(ImgFmt == ImageFormat.Png); Status.Content = "Image Saved to Clipboard"; } else { try { BMP.Save(FileName, ImgFmt); Status.Content = "Image Saved to Disk"; } catch (Exception E) { Status.Content = "Not Saved. " + E.Message; return; } } if (FileName != null && !SaveToClipboard) { Recent.Add(FileName, RecentItemType.Image); } } else { Status.Content = "Not Saved - Image taken was Empty"; } }
public Bitmap Capture(bool Cursor) { return(ScreenShot.Capture(Screen, Cursor)); }
/// <summary> /// 开始截图 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void trayMenuScreenShot_Click(object sender, EventArgs e) { ScreenShot.Capture(); }
public async Task <Bitmap> GetScreenShot() { Bitmap bmp = null; var selectedVideoSource = VideoViewModel.SelectedVideoSource; var includeCursor = Settings.IncludeCursor; switch (VideoViewModel.SelectedVideoSourceKind) { case WindowSourceProvider _: IWindow hWnd = Window.DesktopWindow; switch (selectedVideoSource) { case WindowItem windowItem: hWnd = windowItem.Window; break; case WindowPickerItem windowPicker: var picked = windowPicker.Picker.PickWindow(); if (picked != null) { hWnd = picked; } else { return(null); } break; } bmp = ScreenShotWindow(hWnd); break; case DeskDuplSourceProvider _: if (selectedVideoSource is DeskDuplItem deskDuplItem) { bmp = ScreenShot.Capture(deskDuplItem.Rectangle, includeCursor); } break; case ScreenSourceProvider _: switch (selectedVideoSource) { case FullScreenItem _: var hide = _mainWindow.IsVisible && Settings.UI.HideOnFullScreenShot; if (hide) { _mainWindow.IsVisible = false; // Ensure that the Window is hidden await Task.Delay(300); } bmp = ScreenShot.Capture(includeCursor); if (hide) { _mainWindow.IsVisible = true; } break; case ScreenPickerItem screenPicker: var picked = screenPicker.Picker.PickScreen(); if (picked != null) { bmp = ScreenShot.Capture(picked.Rectangle, includeCursor); } else { return(null); } break; case ScreenItem screen: bmp = screen.Capture(includeCursor); break; } bmp = bmp?.Transform(Settings.ScreenShots); break; case RegionSourceProvider _: bmp = ScreenShot.Capture(_regionProvider.SelectedRegion, includeCursor); bmp = bmp.Transform(Settings.ScreenShots); break; } return(bmp); }
public async Task <IBitmapImage> GetScreenShot(bool SuppressHide = false) { IBitmapImage bmp = null; var selectedVideoSource = _videoSourcesViewModel.SelectedVideoSourceKind?.Source; var includeCursor = _settings.IncludeCursor; switch (_videoSourcesViewModel.SelectedVideoSourceKind) { case WindowSourceProvider _: var hWnd = _platformServices.DesktopWindow; switch (selectedVideoSource) { case WindowItem windowItem: hWnd = windowItem.Window; break; } bmp = ScreenShotWindow(hWnd); break; case DeskDuplSourceProvider _: if (selectedVideoSource is DeskDuplItem deskDuplItem) { bmp = ScreenShot.Capture(deskDuplItem.Rectangle, includeCursor); } break; case FullScreenSourceProvider _: var hide = !SuppressHide && _mainWindow.IsVisible && _settings.UI.HideOnFullScreenShot; if (hide) { _mainWindow.IsVisible = false; // Ensure that the Window is hidden await Task.Delay(300); } bmp = ScreenShot.Capture(includeCursor); if (hide) { _mainWindow.IsVisible = true; } break; case ScreenSourceProvider _: if (selectedVideoSource is ScreenItem screen) { bmp = ScreenShot.Capture(screen.Screen.Rectangle, includeCursor); } break; case RegionSourceProvider _: bmp = ScreenShot.Capture(_regionProvider.SelectedRegion, includeCursor); break; case WebcamSourceProvider _: bmp = _webcamModel.WebcamCapture?.Capture(GraphicsBitmapLoader.Instance); break; } return(bmp); }