Creating multi-layered screenshots (a BarCamp London hack)

I’m on a slow (gah, engineering works!) train back from an awesome BarCampLondon. I’ve got a ton of notes from so many fascinating talks and sessions, but not quite sure how to share them… they would make for the world’s longest blog post!

But as I have a little time to kill, I thought I’d quickly share a little hack that I pulled together overnight. An old idea, but a fun one – and it’s amazing what beer and interesting people will do for your creativity. 🙂

The hack is a little Windows utility to capture more useful screenshots.

By way of background, when you press the “Print Screen” button, it copies an image of your desktop to the clipboard. Very useful. But it has limitations.

What if a window you want to see in the screenshot image is obscured by another window? Or minimised entirely? That information is lost.

Not with my hack! 🙂

My tool captures “interactive” multi-layered screenshots – a picture of each window is captured separately on it’s own layer. This creates a screenshot that (even after you’ve taken the screenshot) will let you move windows around, hide/restore windows, and change the z-order of windows.

It creates a sort of simulation-like snapshot of what your desktop was like at the time.

It turned out to be more complicated than I expected to implement. There were two main challenges:

Getting a screenshot of each individual window
The native Windows API did let me enumerate all open windows, and take a screenshot of each Window in turn. But windows are not drawn unless they are visible. So if any portion of it is obscured by something else, the screenshot you capture has whatever was in front of it at the time.

So I had to play with the Windows API a little more to bring each Window in turn to the front, before capturing a screenshot of it. This makes for a slightly freaky effect while you run the tool while it cycles through all the open windows, bringing each of them to the front!

To stop you interfering with this and screwing things up, I did find a neat Windows API call I’d not seen before – BlockInput. Calling this prevents any keyboard or mouse input until I’ve finished doing my stuff with windows.

Creating a multi-layered image
This was not as easy as I thought. I couldn’t find any simple API’s for creating multi-layered images. I guess I should have guessed that there wouldn’t be an easy API to create PhotoShop-format images, for example.

In the end, I came across a scripting language for Gimp – ScriptFu. This lets you run Gimp commands in batch mode, without needing to run the full GIMP application, or load the full palette, tools, or graphical interface.

It’s an interesting Lisp-based language – a little quirky, but after a couple of hours playing I was able to come up with a small script that took my collection of single/non-layered images, and merged them together into a multi-layered image. It even let me label each layer with the relevant window title, and move it to the coordinates of the window at the time the screenshot was captured.

This does mean that my little tool depends on Gimp being installed as a prerequisite. A pain, I know – but I couldn’t find a nicer way to do it. And you really should have Gimp installed anyway, you know – it’s lovely. 😉

If you want to try it out, you are very welcome to have a play with it – download it here. Just run it from a command line for the first time to set it up. Screenshots are saved to the root C directory, named with a timestamp, and saved in Gimp’s xcf file format.

(Please remember, this was written overnight, after a not-inconsiderable amount of beer. And virtually no sleep. So while I don’t think it will do anything horrible to your computer, please don’t shout too loud if it does anything unexpected!).

Tags: , , , , ,

4 Responses to “Creating multi-layered screenshots (a BarCamp London hack)”

  1. Anton Piatek says:

    Got any screenshots? :p
    (can’t try it as don’t have windows)

  2. Waleed says:

    Hmm..

    I think that will be much simpler when done using http://www.autohotkey.com/

    but, windows will not be captured in layers, instead they can be different file names in sequence

    I guess, i will give it a try when I get some time.

  3. Fran says:

    broken link =(

  4. dale says:

    Ah – looks like my web host has stopped allowing me to provide .exe files for download.

    I’ve wrapped it in a zip and put it at
    http://dalelane.co.uk/files/bLADE%20Screen.zip – is that any better?