private async void snipBtn_ClickAsync(object sender, EventArgs e) { if (timerCombobox.SelectedIndex != -1) { Hide(); await DelayScreenshot(timerCombobox.SelectedIndex); } if (isFreeFormSnipActive) { var takenPictureBmp = Snip.Snipping(); if (takenPictureBmp != null) { Show(); notificationLabel.Text = "Picture taken sucessfuly! Ready to be exported"; notificationLabel.ForeColor = Color.Green; if (autosaveCheckBox.Checked) { Clipboard.SetImage(takenPictureBmp); notificationLabel.Text = "Picture saved to clipboard"; } else { SaveFileDialog saveDialog = new SaveFileDialog(); saveDialog.Filter = "Images|*.png;*.bmp;*.jpg"; ImageFormat format = ImageFormat.Png; if (saveDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string ext = System.IO.Path.GetExtension(saveDialog.FileName); switch (ext) { case ".jpg": format = ImageFormat.Jpeg; break; case ".bmp": format = ImageFormat.Bmp; break; } Bitmap pictureToSave = new Bitmap(takenPictureBmp); pictureToSave.Save(saveDialog.FileName, format); } } } } else { } }
public static Image Snipping() { //var rc = Screen.PrimaryScreen.Bounds; using (Bitmap bmp = new Bitmap(SystemInformation.VirtualScreen.Width, SystemInformation.VirtualScreen.Height , PixelFormat.Format32bppPArgb)) { using (Graphics gr = Graphics.FromImage(bmp)) gr.CopyFromScreen(SystemInformation.VirtualScreen.Left, SystemInformation.VirtualScreen.Top, 0, 0, bmp.Size); using (var snipper = new Snip(bmp, new Point(SystemInformation.VirtualScreen.Left, SystemInformation.VirtualScreen.Top))) { if (snipper.ShowDialog() == DialogResult.OK) { return(snipper.Image); } } return(null); } }