public Boolean start(String fileName, String workingDirectory, String screenshotPath) { ProcessStartInfo Info = new ProcessStartInfo { FileName = fileName + ".exe", //"Map Suite Desktop for WinForms App1.exe", WorkingDirectory = workingDirectory, //"E:/Thinkgeo/MapSuite9SamplesUpgrade/Tools/tool/DisplayWmsRasterLayerSample-ForWinForms/DisplayWmsRasterLayer/bin/Debug/" UseShellExecute = false }; Process Proc; try { Proc = Process.Start(Info); } catch (System.ComponentModel.Win32Exception e) { Console.WriteLine("系统找不到指定的程序文件。\r{0}", e); return(false); } //打印出外部程序的开始执行时间 Console.WriteLine(fileName + "截图开始执行时间:{0}", Proc.StartTime); //等待3秒钟 Proc.WaitForExit(10000); ScreenShot s = new ScreenShot(); Image img = s.CaptureWindow(Proc.MainWindowHandle); img.Save(screenshotPath + "/" + fileName + ".png"); //如果这个外部程序没有结束运行则对其强行终止 if (Proc.HasExited == false) { Console.WriteLine("由主程序强行终止外部程序的运行!"); Proc.Kill(); } else { Console.WriteLine("由外部程序正常退出!"); } if (img.Width < 10) { Console.WriteLine(fileName + "截图失败"); return(false); } else { Console.WriteLine(fileName + "截图成功"); return(true); } Console.WriteLine("截图结束运行时间:{0}", Proc.ExitTime); Console.WriteLine(""); }
private async void CaptureScreen() { Settings.SaveNewSettings(urlinput.Text, path.Text, port.Text); ScreenShot screenshot = new ScreenShot(Properties.Settings.Default.URL, Properties.Settings.Default.port, Properties.Settings.Default.path); string response = await screenshot.GetImageDataFromServer(); if (response != null) { var response_window = new Answer(Properties.Settings.Default.URL, response, Properties.Settings.Default.port); response_window.Show(); } screenshot = null; GC.Collect(); GC.WaitForPendingFinalizers(); }
public Boolean start(String fileName, String workingDirectory, String screenshotPath) { Process Proc = new Process(); try { Proc = Process.Start(workingDirectory + fileName); } catch (System.ComponentModel.Win32Exception e) { Console.WriteLine("系统找不到指定的程序文件。\r{0}", e); return(false); } //打印出外部程序的开始执行时间 Console.WriteLine(fileName + "截图开始执行时间:{0}", Proc.StartTime); //等待10秒钟 Proc.WaitForExit(10000); ScreenShot s = new ScreenShot(); Image img = s.CaptureWindow(Proc.MainWindowHandle); img.Save(screenshotPath + "/" + fileName + ".png"); //如果这个外部程序没有结束运行则对其强行终止 if (Proc.HasExited == false) { Console.WriteLine("由主程序强行终止外部程序的运行!"); Proc.Kill(); } else { Console.WriteLine("由外部程序正常退出!"); } if (img.Width < 10) { Console.WriteLine(fileName + "截图失败"); return(false); } else { Console.WriteLine(fileName + "截图成功"); return(true); } Console.WriteLine("截图结束运行时间:{0}", Proc.ExitTime); Console.WriteLine(""); }
static void Main(string[] args) { if (args.Length < 3) { Console.WriteLine("Usage: ScreenShot seconds weeks destDir"); Console.WriteLine("seconds: int, capture screen each X seconds"); Console.WriteLine("weeks: int, delete images older than X weeks"); Console.WriteLine("destDir: string, save images to this folder"); return; } while (true) { try { ScreenShot.CaptureScreen(Convert.ToInt32(args[0]), Convert.ToInt32(args[1]), args[2]); } catch (Exception e) { Console.WriteLine(e.ToString()); Thread.Sleep(120 * 1000); } } }
private void __onClick3() { ScreenShot.GetInstance().CaptureScreenshot(Camera.main, new Rect(100, 100, 300, 300)); }
private void __onClick2() { ScreenShot.GetInstance().CaptureScreenshot(new Rect(200, 120, 200, 200)); }
private void __onClick1() { ScreenShot.GetInstance().CaptureScreenshot(); }