// Image public void AddScreenShot() { try { System.Media.SystemSounds.Exclamation.Play(); images.Add(new Screenshot(ScreenshotHelper.GetFullScreenshot(), GetScreenshotName())); imagesIndex = images.Count - 1; UpdateUI(); } catch (Exception e) { if (MessageBox.Show("Oopsie woopsie, it seems like I cant make that screenshot!\nDo you want to see the error message in detail?", "Error", MessageBoxButtons.YesNo) == DialogResult.Yes) { MessageBox.Show(e.Message + "\n\n" + e.InnerException + "\n\n" + e.StackTrace); } } }
private void PBox_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left && mode == cropMenuItem) { Rectangle crop = GetRectangleFromPoints( ZoomPicBoxCoordsToImageCoords(pMouseDown, pBox), ZoomPicBoxCoordsToImageCoords(pMouseCurrently, pBox)); if (crop.Width == 0 || crop.Height == 0) { isMouseDown = false; return; } images.Insert(imagesIndex + 1, new Screenshot(ScreenshotHelper.CropImage(images[imagesIndex].Image, crop), images[imagesIndex].FileName + "_CROPPED")); imagesIndex += 1; UpdateUI(); } isMouseDown = false; }
private void PictureBox1_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { Rectangle crop = GetRectangleFromPoints( new Point((int)(pMouseDown.X * (double)fullScreenshot.Width / pBox.Width), (int)(pMouseDown.Y * (double)fullScreenshot.Height / pBox.Height)), new Point((int)(pMouseCurrently.X * (double)fullScreenshot.Width / pBox.Width), (int)(pMouseCurrently.Y * (double)fullScreenshot.Height / pBox.Height))); if (crop.Width == 0 || crop.Height == 0) { MessageBox.Show("Thats a little too small, dont you think?", "Too Smol", MessageBoxButtons.OK); IsLeftMouseDown = false; return; } output = ScreenshotHelper.CropImage(fullScreenshot, crop); IsLeftMouseDown = false; this.Close(); } else if (e.Button == MouseButtons.Middle) { gifArea = GetRectangleFromPoints( new Point((int)((pMouseDown.X + ScreenshotHelper.allScreenBounds.X) * (double)fullScreenshot.Width / pBox.Width), (int)((pMouseDown.Y + ScreenshotHelper.allScreenBounds.Y) * (double)fullScreenshot.Height / pBox.Height)), new Point((int)((pMouseCurrently.X + ScreenshotHelper.allScreenBounds.X) * (double)fullScreenshot.Width / pBox.Width), (int)((pMouseCurrently.Y + ScreenshotHelper.allScreenBounds.Y) * (double)fullScreenshot.Height / pBox.Height))); if (gifArea.Width == 0 || gifArea.Height == 0) { MessageBox.Show("Thats a little too small, dont you think?", "Too Smol", MessageBoxButtons.OK); IsMiddleMouseDown = false; return; } IsMiddleMouseDown = false; Debug.WriteLine("Set gif area to: " + gifArea); this.Close(); } else if (e.Button == MouseButtons.Right) { this.Close(); } }
private void MainForm_Load(object sender, EventArgs e) { if (config.Default.path == "<Unset>" || !Directory.Exists(config.Default.path)) { config.Default.path = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); } if (config.Default.windowSize.Width != 0) { Size = config.Default.windowSize; } if (config.Default.PrimaryColor.Name == "0") { config.Default.PrimaryColor = Color.Red; } if (config.Default.instantShortcut.IsNullOrWhiteSpace()) { instantKeys = Shortcut.DefaultInstantKeys; } else { instantKeys = new Shortcut().FromString(config.Default.instantShortcut); } if (config.Default.cropShortcut.IsNullOrWhiteSpace()) { cropKeys = Shortcut.DefaultCropKeys; } else { cropKeys = new Shortcut().FromString(config.Default.cropShortcut); } if (config.Default.gifShortcut.IsNullOrWhiteSpace()) { gifKeys = Shortcut.DefaultGifKeys; } else { gifKeys = new Shortcut().FromString(config.Default.gifShortcut); } middleButtons.Add(bSave); middleButtons.Add(bDelete); int MiddleButtonWidth = 0; foreach (Button B in middleButtons) { MiddleButtonWidth += B.Width + 6; } MiddleButtonWidth -= 6; for (int i = 0; i < middleButtons.Count; i++) { middleButtons[i].Location = new Point(Width / 2 - MiddleButtonWidth / 2 + i * (6 + middleButtons[i].Width) - 8, middleButtons[i].Location.Y); } int MinWidth = MiddleButtonWidth + 6 * (middleButtons.Count + 1) + 90; MinimumSize = new Size(MinWidth, MinWidth); MainForm_SizeChanged(null, EventArgs.Empty); Minimize(); string[] files = Directory.GetFiles(config.Default.path). Where(s => (s.EndsWith(".png") || s.EndsWith(".gif")) && Path.GetFileNameWithoutExtension(s).Contains("Screenshot_")). OrderBy(x => x). Reverse(). ToArray(); if (files.Length > 0) { images.AddRange(files.Select(x => new Screenshot(x)).ToArray()); } else { images.Add(new Screenshot(ScreenshotHelper.GetFullScreenshot(), GetScreenshotName())); } imagesIndex = images.Count - 1; noneMenuItem.Checked = true; UpdateWindowRatioWidth(); UpdateUI(); }
private void PBox_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { ContextMenu m = new ContextMenu(); //m.MenuItems.Add(new MenuItem("Fix Width Ratio", ((object s, EventArgs ev) => //{ // try // { // UpdateWindowRatioWidth(); // } // catch { } //}))); //m.MenuItems.Add(new MenuItem("Fix Height Ratio", ((object s, EventArgs ev) => //{ // try // { // UpdateWindowRatioHeight(); // } // catch { } //}))); GraphicsUnit Unit = GraphicsUnit.Pixel; if (images[imagesIndex].Image.GetBounds(ref Unit).Width == ScreenshotHelper.allScreenBounds.Width) { int i = 1; foreach (Screen S in Screen.AllScreens) { m.MenuItems.Add(new MenuItem("Crop to " + i.ToShitEnglishNumberThingy() + " Screen", ((object s, EventArgs ev) => { try { images.Insert(imagesIndex + 1, new Screenshot(ScreenshotHelper.CropImage(images[imagesIndex].Image, new Rectangle(S.Bounds.X - ScreenshotHelper.allScreenBounds.X, S.Bounds.Y - ScreenshotHelper.allScreenBounds.Y, S.Bounds.Width, S.Bounds.Height)), images[imagesIndex].FileName + "_CROPPED")); imagesIndex++; UpdateUI(); } catch { } }))); i++; } } m.MenuItems.Add(new MenuItem("1:1 Size", ((object s, EventArgs ev) => { try { SetOriginalSize(); } catch { } }))); m.MenuItems.Add(new MenuItem("Smol Size", ((object s, EventArgs ev) => { try { Height = 350; Width = 350; CenterAroundMouse(); } catch { } }))); m.Show(pBox, e.Location); } }
// GIF public void StartRecordingGif() { if (processingGif | recordingGif) { return; } if (snipper.gifArea.Width == 0 || snipper.gifArea.Height == 0) { if (!shownGifSnipperHelp) { shownGifSnipperHelp = true; DialogResult result = MessageBox.Show("You need to select an gif area in the SelectionForm™ before recording a gif!", "Missing Gif Area", MessageBoxButtons.OK); if (result == DialogResult.OK) { shownGifSnipperHelp = false; } } return; } processingGif = true; recordingGif = true; gifShots.Clear(); Task.Factory.StartNew(() => { List <Task> runners = new List <Task>(); for (int i = 0; i < 750 && recordingGif; i++) { runners.Add(Task.Factory.StartNew(() => { gifShots.Add(ScreenshotHelper.GetRectScreenshot(snipper.gifArea)); Debug.WriteLine($"Made gif shot {i}!"); })); Task.Delay(33).Wait(); } Debug.WriteLine("waiting for close..."); Task.WaitAll(runners.ToArray()); Debug.WriteLine("closed"); string path = config.Default.path + "\\" + GetScreenshotName() + ".gif"; using (FileStream s = new FileStream(path, FileMode.Create)) { using AnimatedGifCreator c = new AnimatedGifCreator(s, 40); foreach (Bitmap b in gifShots) { c.AddFrame(b, -1, GifQuality.Default); } } images.Add(new Screenshot(path)); imagesIndex = images.Count - 1; CurrentScreenshot.Save(); this.InvokeIfRequired(() => UpdateUI()); processingGif = false; }); }