static void Main(string[] args) { Console.WriteLine("Taking screenshot... OS : {0} ", Environment.OSVersion.Platform); using (var screen = ScreenshotCapture.TakeScreenshot()) { screen.Save(Path.Combine(Environment.CurrentDirectory, "Screenshot.jpg"), ImageFormat.Jpeg); } Console.WriteLine("Done"); Console.ReadLine(); }
private TrackerPayload GetTrackerPayload() { var world = "./images/world.jpg"; var tracker = new Tracker(); using (var minimap = new TempFile("jpeg")) using (var screencapturer = new ScreenshotCapture()) { screencapturer.TakeScreenshot(minimap.Path); var coord = tracker.Match(minimap.Path, world); return(new TrackerPayload() { Coord = coord }); } }
private async void Window_MouseUp(object sender, MouseButtonEventArgs e) { if (_dragging) { var end = e.GetPosition(this); var selection = GetSelection(end); if (!selection.IsEmpty) { // Hide overlay before capturing screenshot Hide(); await Task.Delay(TimeSpan.FromMilliseconds(100)); // Capture screenshot of selected region var original = new Bitmap(ScreenshotCapture.TakeScreenshot()) .Crop(selection) .CropToContent(); // Invert colors of screenshot if needed to ensure good OCR result var modified = original.Scale(2); if (modified.IsDark(50)) { modified = modified.InvertColors(); } var text = modified.ToBlackAndWhite().Ocr().Item1; var pair = new BitmapTextPair( original.ToImageSource(), modified.ToImageSource(), text ); // Launch snippet manager _ocrSnippetWindow.Model.BitmapPairs.Add(pair); _ocrSnippetWindow.Show(); Close(); return; } } _dragging = false; _startDrag = default; e.Handled = true; }
public void TestFinished(TestResult result) { try { if (!result.IsSuccess && result.ResultState != ResultState.Ignored && result.ResultState != ResultState.Skipped && result.ResultState != ResultState.NotRunnable) { Debug.Print(string.Format("{0}\n{1}", result.Message, result.StackTrace)); // Try to get screenshots of application var dirPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\Screenshots"; Directory.CreateDirectory(dirPath); var fileName = Path.GetInvalidFileNameChars().Aggregate(result.Test.TestName.Name, (current, c) => current.Replace(c.ToString(CultureInfo.InvariantCulture), string.Empty)); if (dirPath.Length > 249) { Debug.Print("Directory path is very long!"); throw new Exception("Directory path is very long!"); } if (dirPath.Length + fileName.Length >= 249) { fileName = fileName.Substring(0, 249 - dirPath.Length); } Debug.Print(string.Format("Taking screenshot: {0}\\{1}", dirPath, fileName)); try { ScreenshotCapture.TakeScreenshot(true).Save(string.Format("{0}\\{1}_Full.png", dirPath, fileName), ImageFormat.Png); } catch (Exception exp) { } } Debug.Print(string.Format("Test Result : {0} and Test Name : {1}", result.ResultState, result.Name)); Application.Close(); } catch (Exception exp) { Debug.Print(exp.Message, exp); } }
static void Main(string[] args) { //var minimap = "./images/minimap_org.jpg"; var world = "./images/world.jpg"; var tracker = new Tracker(); using (var minimap = new TempFile("jpeg")) using (var screencapturer = new ScreenshotCapture()) { screencapturer.TakeScreenshot(minimap.Path); var coord = tracker.Match(minimap.Path, world); } //var minimaps = Directory.EnumerateFiles("./screenshots/", "*.png"); //foreach (var minimap in minimaps) //{ // tracker.Match(minimap, world); //} }
public Bitmap TakeScreenshot() { return(new Bitmap(ScreenshotCapture.TakeScreenshot())); }