Skip to content

Instantly share code, notes, and snippets.

@aoisensi
Created October 24, 2013 02:07
Show Gist options
  • Save aoisensi/7130132 to your computer and use it in GitHub Desktop.
Save aoisensi/7130132 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace gyawinzo
{
static class Program
{
static Point p1, p2;
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form form = new Form();
form.Opacity = 0.2;
form.WindowState = FormWindowState.Maximized;
form.FormBorderStyle = FormBorderStyle.None;
form.TopMost = true;
form.MouseClick += (sender, e) => {if (e.Button == MouseButtons.Right) ((Form)sender).Close();};
form.MouseDown += (sender, e) => {
if (e.Button == MouseButtons.Left)
p1 = e.Location;
};
form.MouseUp += (sender, e) => {
if (e.Button == MouseButtons.Left)
{
p2 = e.Location;
((Form)sender).Close();
SaveImage();
}
};
Application.Run(form);
}
static void SaveImage()
{
Rectangle rect = new Rectangle(p1, Size.Subtract((Size)p2, (Size)p1));
if (rect.Size.Width * rect.Size.Height < 16) return;
Bitmap bmp = new Bitmap(rect.Width, rect.Height);
using (Graphics g = Graphics.FromImage(bmp))
{
g.CopyFromScreen(rect.X, rect.Y, 0, 0, rect.Size, CopyPixelOperation.SourceCopy);
}
DateTime now = DateTime.Now;
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
path += "\\Gyawinzo\\";
path += now.ToString("yyyy-MM-dd");
path += "\\";
Directory.CreateDirectory(path);
path += now.ToString("HH-mm-ss");
path += ".png";
bmp.Save(path);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment