private void GrabItem(bool saveScreenshot = false) { Stopwatch sw = new Stopwatch(); var cursorPos = Cursor.Position; sw.Start(); this.Opacity = 0; var screen = TakeScreenshot(ref cursorPos); this.Opacity = 1; var ie = new ItemExtractor(screen, cursorPos); Item item = null; try { item = ie.ExtractItem(); } catch { } sw.Stop(); Debug.Print("Time for extraction: " + sw.Elapsed.ToString()); if (item == null) { Status("No item found"); } else { if (options.ItemToClipboard) Clipboard.SetImage(item.Image); items.Add(item); itemListBox1.SelectedIndex = itemListBox1.Items.Count - 1; Debug.Print("{0} items in ListBox", itemListBox1.Items.Count); UpdateLabel(); } if (saveScreenshot) { // save picture for future testing string baseName; if (item == null) baseName = string.Format("itemat-{0:yyyy-MM-dd-HH-mm-ss}-P{1}-{2}", DateTime.UtcNow, cursorPos.X, cursorPos.Y); else baseName = string.Format( "itemat-{0:yyyy-MM-dd-HH-mm-ss}-P{1}-{2}-R{3}-{4}-{5}-{6}", DateTime.UtcNow, cursorPos.X, cursorPos.Y, ie.ItemFrame.X, ie.ItemFrame.Y, ie.ItemFrame.Width, ie.ItemFrame.Height); var picFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); var testFolder = Path.Combine(picFolder, "ExtractTest"); if (!Directory.Exists(testFolder)) Directory.CreateDirectory(testFolder); var file = Path.Combine(testFolder, baseName + ".in.png"); screen.Save(file); if (item != null) { var outfile = Path.Combine(testFolder, baseName + ".out.png"); item.Image.Save(outfile); var titlefile = Path.Combine(testFolder, baseName + ".title.png"); item.Title.Save(titlefile); } } }
private void GrabItem(bool saveScreenshot = false) { Stopwatch sw = new Stopwatch(); var cursorPos = Cursor.Position; sw.Start(); this.Opacity = 0; var screen = TakeScreenshot(ref cursorPos); this.Opacity = 1; var ie = new ItemExtractor(screen, cursorPos); Item item = null; try { item = ie.ExtractItem(); } catch { } sw.Stop(); Debug.Print("Time for extraction: " + sw.Elapsed.ToString()); if (item == null) { Status("No item found"); } else { if (options.ItemToClipboard) { Clipboard.SetImage(item.Image); } items.Add(item); itemListBox1.SelectedIndex = itemListBox1.Items.Count - 1; Debug.Print("{0} items in ListBox", itemListBox1.Items.Count); UpdateLabel(); } if (saveScreenshot) { // save picture for future testing string baseName; if (item == null) { baseName = string.Format("itemat-{0:yyyy-MM-dd-HH-mm-ss}-P{1}-{2}", DateTime.UtcNow, cursorPos.X, cursorPos.Y); } else { baseName = string.Format( "itemat-{0:yyyy-MM-dd-HH-mm-ss}-P{1}-{2}-R{3}-{4}-{5}-{6}", DateTime.UtcNow, cursorPos.X, cursorPos.Y, ie.ItemFrame.X, ie.ItemFrame.Y, ie.ItemFrame.Width, ie.ItemFrame.Height); } var picFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); var testFolder = Path.Combine(picFolder, "ExtractTest"); if (!Directory.Exists(testFolder)) { Directory.CreateDirectory(testFolder); } var file = Path.Combine(testFolder, baseName + ".in.png"); screen.Save(file); if (item != null) { var outfile = Path.Combine(testFolder, baseName + ".out.png"); item.Image.Save(outfile); var titlefile = Path.Combine(testFolder, baseName + ".title.png"); item.Title.Save(titlefile); } } }