Click here to Skip to main content
Click here to Skip to main content

NinjaSnipper - Fast Screenshot Capturing for Windows

, 30 Sep 2012 GPL3
Rate this:
Please Sign up or sign in to vote.
Productivity oriented snipping tool for Windows

Introduction

There are many screenshot/screensnipping tools out there and none of them performed as I needed them. Nevertheless I gathered impressions and decided to compile the best ideas into a product, I am confident that you will like it.

My requirements for a snipping tool (all implemented) are as follows:

  1. Be able to select part of the screen with your mouse and save it to a file and/or copy it to the clipboard.
  2. Also detect pressing the PrintScreen key and save the clipboard contents to a file.
  3. Save the screenshots automatically to some predefined location with a default image format (not open a dialog every time, nor an editor)
  4. However be able to specify a different location and image format every now and then.
  5. No GUI. I wanted it to run in the background (in this case, the system tray).
  6. Activate it via keyboard shortcut. It is a deal breaker if you have to navigate to the app for every screenshot, when you are making a lot of them.
  7. Work on multiple monitors!

Background

This is more of a Tips n' Tricks entry. I will only be addressing key problems/solutions with brief descriptions and references where I see fit. Not all of the requirements will be discussed as not all of them present a "challenge" to the programmer.

For the project, I decided to use C# as it seems the most appropriate choice for a Windows application. Furthermore for the PrintScreen keys I was going to use hooks, which is of course OS specific, so there was no way to make a OS portable application in a short time. Having said that, the application has only been tested on Windows 7 64bit with .NET 4 and Vista 32bit. The executables attached to this tip may not work on other platforms.

I expect the source code to be portable to older versions of .NET and Windows. Feedback would be appreciated.

Using the Code

There are several classes, each dedicated to a specific task. There are several secondary classes, such as the Settings Form, Help Form, etc. It is not the purpose of this tip to discuss how the application is built so this is as much as I will say about the code structure.

The SnippingTool that comes with Windows 7 has a really nice interface. Once you start it, it dims the screen and you can draw a transparent rectangle on the screen, marking the area you want to copy. One way to do this is to create a form with no controls, maximize it, draw on it with the mouse, pick the coordinates and take a screen shot. Really, a straightforward task! However when you have multiple monitors, the form would maximize only on one of them. So I needed to resize the form manually. The Virtual Screen is the (rectangular) area that includes all the monitors.

You can get the origin and the size like this:

SystemInformation.VirtualScreen.X

The origin may have negative coordinates. Beware when calculating! The resizing presented me with a challenge due to my lack of understanding! Merely setting the size and location of my form to those of the virtual screen was not enough. It did indeed resize the form but not the area on which I could draw. Maximizing the form took care of everything, but now I had to do it manually, whatever it may be that had to be done. Without going into detail (keywords being clientArea, clippingArea, ClientRectangle, etc.), the problem was solved by the following line:

this.Bounds = new Rectangle(SystemInformation.VirtualScreen.X, SystemInformation.VirtualScreen.Y, 
    SystemInformation.VirtualScreen.Width, SystemInformation.VirtualScreen.Height);

Drawing on the form was an easy task:

Graphics g = this.CreateGraphics(); // where *this* is my form
g.DrawRectangle(new Pen(Color.Red, 3), x, y, width, height);

As for making the screenshot programmatically, I was going to go with Win32 API if I hadn't found this similar project, Tebo Basic C Screen Capture Application which reveals a neat solution:

Bitmap bitmap = new Bitmap(width, height));
Graphics g = Graphics.FromImage(bitmap)
g.CopyFromScreen(SourcePoint, DestinationPoint, SelectionRectangle.Size);

Just for the sake of completeness (although by no means can this make the tip complete) saving an image to a file:

bitmap/img.Save("path\\file.name", ImageFormat.Jpeg); // or any other format 

Retrieving an image from the clipboard and setting one is as easy as this:

Image img = Clipboard.GetImage();
Clipboard.SetImage(img);

For the PrintScreen hook, I blatantly copied the InterceptKeys class into my project from here.

It is pretty basic and self explanatory. Caution should be exercised when catching the KeyDown event nevertheless, as the order of propagating the event between applications is not set, and reading out the clipboard may occur before the new screenshot has been taken.

Since I was already using hooks, I just added a hotkey combination, namely Ctrl + Space + C.

Points of Interest

Places for improvement:

  • a list of default locations to save an image to
  • a list of commands/programs to be executed on capture
  • quality of pictures could be better

History

  • 2012-06-26 bug fix, files updated

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

Share

About the Author

Zaraken

Germany Germany
Will program for food

Comments and Discussions

 
QuestionVery nice tool PinmemberRoss MacFarlane12-Oct-12 4:50 
AnswerRe: Very nice tool PinmemberZaraken12-Oct-12 11:52 
GeneralRe: Very nice tool PinmemberRoss MacFarlane14-Oct-12 23:56 
GeneralRe: Very nice tool PinmemberZaraken15-Oct-12 13:27 
GeneralMy vote of 4 PinmemberAl-Samman Mahmoud2-Oct-12 10:22 
GeneralMy vote of 5 PinmemberSuraj S Koneri30-Sep-12 23:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.141022.1 | Last Updated 1 Oct 2012
Article Copyright 2012 by Zaraken
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid