Jump to content

My Screenshot plugin that does not clobber the clipboard


mihi
 Share

Recommended Posts

Hi,

I often have to take screenshots at work, but want to keep my clipboard contents. Or I want to take a screenshot of a shaped (non-rectangular) window or include the mouse cursor. Or simulate mouse wheel events and stitch the screenshots together (the last feature still being very experimental). The builtin screenshot feature of at least Win2003 cannot do all this.

As my main image editor is Paint.NET, I wrote a Paint.NET plugin for this, and I decided to share it here if anyone else might find it useful, too.

Unfortunately, Paint.NET does not really support "Acquire" plugins that show some GUI and then import an image (might also be useful for other plugins like the TWAIN plugin), so the best way I could find is have a FileType plugin that "opens" a config file and creates a screenshot from it, and if it cannot, it will return a small blank image. (It is really quick as the file is almost always in my recent file list). You can The plugin does not support "saving" an image, but you can change the options and create a new config file from it.

An example config file is included in the download. A standalone screenshot tool (that has the same options) is included as well, in case you want to take screenshots not from Paint.NET.

As it uses code released under LGPL license, the complete source code is included in the download.

[edit: Seems that my attachment did not make it though - therefore I uploaded it here]

ScreenShooter-0.1.png

Have fun,

mihi

Edited by mihi
Link to comment
Share on other sites

Unfortunately, Paint.NET does not really support "Acquire" plugins that show some GUI and then import an image (might also be useful for other plugins like the TWAIN plugin), so the best way I could find is have a FileType plugin that "opens" a config file and creates a screenshot from it, and if it cannot, it will return a small blank image. (It is really quick as the file is almost always in my recent file list). You can The plugin does not support "saving" an image, but you can change the options and create a new config file from it.

A better option might be to write it as a separate program that opens the screenshot in Paint.NET (which is what Window Clippings does with its Paint.NET integration). Or write it as an effect that draws the screenshot onto the canvas, which isn't perfect but better IMO. Accomplishing it with a FileType plugins might get your plugin deleted:

FileType plugins must not masquerade as "export" plugins. Nor must they have other "side effects."

A plugin for "export to photobucket" would be completely inappropriate, for instance. The user experience would be completely inappropriate: the user would asked to choose a file, and then your UI would upload the file somewhere, and then the user would have a 0-byte file on their disk because you ignored the Stream object that Paint.NET handed to you. These types of plugins will be deleted.

KaHuc.png
Link to comment
Share on other sites

A better option might be to write it as a separate program that opens the screenshot in Paint.NET (which is what Window Clippings does with its Paint.NET integration)

Yes, that's what I was trying before. But it happened too often that I accidentally saved the edited screenshot as the temporary filename that was created by the tool (and overwritten the next time, as I don't want to clutter my temp dir with hundreds of screenshots a day either). Having a filetype plugin at least ensures I cannot accdentally save it under the same name after having edited it.

Or write it as an effect that draws the screenshot onto the canvas, which isn't perfect but better IMO.

An effect will clobber the currently opened image (if any), though.

Can an effect plugin result in a different size canvas than the original image? Then it might be a nice idea. If I have to crop the image manually, all the object detection stuff in my screenshot tool is useless.

Accomplishing it with a FileType plugins might get your plugin deleted:

So then it will, I don't care. Thought I might share it with the world (that's what open source is about according to Eric Raymond, someone codes something to scratch a personal itch and shares it with the world), but if the world does not like it, it does not matter to me. You cannot prevent myself from using it, hopefully (Or is there some kind of kill bit in Paint.NET that will disable the plugin in next Paint.NET version?).

Regards,

mihi

Link to comment
Share on other sites

Yes, that's what I was trying before. But it happened too often that I accidentally saved the edited screenshot as the temporary filename that was created by the tool (and overwritten the next time, as I don't want to clutter my temp dir with hundreds of screenshots a day either). Having a filetype plugin at least ensures I cannot accdentally save it under the same name after having edited it.

Window Clippings somehow opens the captured screenshot in Paint.NET as untitled. If you contact Rick, he might be able to help you do this.

An effect will clobber the currently opened image (if any), though.

If someone runs the plugin, they've presumably created a new image for that purpose.

Can an effect plugin result in a different size canvas than the original image? Then it might be a nice idea. If I have to crop the image manually, all the object detection stuff in my screenshot tool is useless.

No.

So then it will, I don't care. Thought I might share it with the world (that's what open source is about according to Eric Raymond, someone codes something to scratch a personal itch and shares it with the world), but if the world does not like it, it does not matter to me. You cannot prevent myself from using it, hopefully (Or is there some kind of kill bit in Paint.NET that will disable the plugin in next Paint.NET version?).

I'm not the one that would delete it, but it would be a shame if it was. Yes, plugins are often blacklisted in updates, but that wouldn't stop you using it yourself.

KaHuc.png
Link to comment
Share on other sites

(Edited to remove / from /untitled)

Simon's right. This is more appropriately done as an external utility.

1. Save the image to somewhere in %TEMP%.

2. Add that file name to the delete-on-next-reboot list that Windows maintains. The exact function name eludes me, but it's there.

3. Figure out where Paint.NET is installed: access HKEY_LOCAL_MACHINE / Software / Paint.NET, and get the value of the TARGETDIR key. This gives you the directory Paint.NET (and thus PaintDotNet.exe) is in.

--> As a corollary, if this key doesn't exist, then Paint.NET isn't installed.

4. Launch %TARGETDIR%\PaintDotNet.exe with untitled:FileNameGoesHere

2* As an alternative to adding it to the delete-on-reboot list, you can also try this:

a) Open the file for ReadWrite access, Read sharing, and Delete-on-Close.

http://msdn.microsof...y/d0y914c5.aspx

new FileStream("whatever.png", FileMode.Create, FileAccess.ReadWrite, FileShare.Read, 4096, FileOptions.DeleteOnClose)

b ) Write your screenshot to the file

c) Flush() the stream

d) BEFORE you close the Stream, launch Paint.NET with untitled:whatever.png

e) Once Paint.NET has finished opening, you can close the Stream. However, there's no deterministic way to figure this out. You could just wait 5 minutes. I think that any reasonable system will be able to start up Paint.NET and open an image within 5 minutes ...

The key here is that Windows will delete the file once all handles have been closed. Technically you could close the file as soon as Paint.NET has opened it for reading, although there's no way for you to determine when that happens. Paint.NET doesn't access a file again after it's read all its contents, unless the user saves. And since you're using /untitled:, it doesn't even keep track of what the original filename was

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

Also, as an alternative to all this, I highly recommend just buying a license for Window Clippings, http://www.windowclippings.com . It works really well; it even grabs the alpha channel when using Aero Glass on Win7/Vista. I think it's safe to say that the hours you'll spend writing your own screenshot utility is worth far more than the $35 that Window Clippings costs. (And this isn't just a shameless plug. I use WindowClippings myself all the time.)

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

Hello Rick,

thank you for your answers.

4. Launch %TARGETDIR%\PaintDotNet.exe with /untitled:FileNameGoesHere

That step does not seem to work for me. I tried the filename with path, without path, replaced the colon by different other characters, used quotation marks at various places, tried it with a path without spaces, but I guess I am just to stupid to make this work (using version 3.5.6). It just opens with an empty untitled document, and in case I use a space as separator (making the arguments two) I get a normal file opened that can be saved normally...

(edit: Forget it, I should have left out the initial slash, and it works now)

e) Once Paint.NET has finished opening, you can close the Stream. However, there's no deterministic way to figure this out. You could just wait 5 minutes. I think that any reasonable system will be able to start up Paint.NET and open an image within 5 minutes ...

As I'll have the tool running in the background and wait for a hotkey, I'll just delete the file when the user presses the hotkey the next time or closed the utility completely (which will usually happen at shutdown).

Also, as an alternative to all this, I highly recommend just buying a license for Window Clippings, http://www.windowclippings.com . It works really well; it even grabs the alpha channel when using Aero Glass on Win7/Vista. I think it's safe to say that the hours you'll spend writing your own screenshot utility is worth far more than the $35 that Window Clippings costs. (And this isn't just a shameless plug. I use WindowClippings myself all the time.)

Unfortunately, I cannot find system requirements on the website, and it does not install on my XP Pro machine at home (installer crashes in the middle). At work we are "forced" (by IIS extensions / COM components we are still using from the last millennium that do not work on anything more recent) to develop on 2003 machines, and if it does not work there (or is not able to create a scrolling screenshot of the "Add/Remove Programs" list, where most free screenshot tools fail as it is completely owner drawn and does not really provide screenreader hints) it does not help my main use case. Yes, I know that you can get all the info of that list from the registry, but that does not help me either.

And when I think about the processes needed to get an approval for installing anything not written ourselves on our development machines at my workplace, I won't even try. Even if 35$ is cheaper than the hours I'll spend on writing my own tool. (On the other hand, if it was easy to install your own software, I wouldn't have bothered trying to use Paint.NET at all and just installed GIMP like on my home machine, and I definitely would never have ended up here in this forum, and have missed a good graphics program to recommend to people who don't like GIMP...)

(edit: Ok, I found the 2.1 version which works on XP, but cannot do any scrolling screenshots and not capture screenreader objects either. At least on XP, PicPick (which costs 20$ and is free for non-commercial use) has more features. Don't know about Vista/7 though.)

Regards,

mihi

(edit2: I updated the zipfile linked above to include both the original plugin and the standalone version for Paint.NET)

Edited by mihi
Link to comment
Share on other sites

That step does not seem to work for me. I tried the filename with path, without path, replaced the colon by different other characters, used quotation marks at various places, tried it with a path without spaces, but I guess I am just to stupid to make this work (using version 3.5.6). It just opens with an empty untitled document, and in case I use a space as separator (making the arguments two) I get a normal file opened that can be saved normally...

Try it without the slash. e.g.

C:\Program Files\Paint.NET\PaintDotNet.exe untitled:C:\image.png

KaHuc.png
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...