Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.Windows.Forms;
- using System.IO;
- namespace ScreenSnap
- {
- public partial class Main : Form
- {
- #region METHODS
- #region CONSTRUCTORS
- public Main()
- {
- InitializeComponent();
- TextBoxFolder.Text = Application.StartupPath;
- }
- #endregion
- public Image ImageCapture(int Width, int Height, int X, int Y)
- {
- this.Opacity = 0;
- Rectangle ScreenBounds = new Rectangle(X, Y, Width, Height);
- Bitmap Screenshot = new Bitmap(ScreenBounds.Width, ScreenBounds.Height, PixelFormat.Format32bppArgb);
- Graphics ScreenGraph = Graphics.FromImage(Screenshot);
- ScreenGraph.CopyFromScreen(ScreenBounds.X, ScreenBounds.Y, 0, 0, ScreenBounds.Size, CopyPixelOperation.SourceCopy);
- Image Img = (Image)Screenshot;
- this.Opacity = 100;
- return Img;
- }
- public void ImageSave(Image Img)
- {
- if (Directory.Exists(TextBoxFolder.Text))
- {
- string Name = TextBoxFolder.Text + @"\" + TextBoxFileName.Text + (DateTime.Now.ToFileTime()) + ".jpg";
- Img.Save(Name, ImageFormat.Jpeg);
- }
- else
- MessageBox.Show("Invalid folder", "Error");
- }
- #endregion
- #region EVENTS
- private void ButtonScreenshot_Click(object sender, EventArgs e)
- {
- try
- {
- ImageSave(ImageCapture(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height,
- Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y));
- }
- catch
- {
- MessageBox.Show("Unknow error!", "Error");
- }
- }
- private void ButtonScreenshotWindow_Click(object sender, EventArgs e)
- {
- try
- {
- /**
- ImageCapture(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height,
- Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y);
- ImageSave();
- /**/
- }
- catch
- {
- MessageBox.Show("Unknow error!", "Error");
- }
- }
- private void ButtonFolderBrowse_Click(object sender, EventArgs e)
- {
- if (FolderBrowserDialogSave.ShowDialog() == DialogResult.OK)
- TextBoxFolder.Text = FolderBrowserDialogSave.SelectedPath;
- }
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement