Rick Strahl's Web Log

Wind, waves, code and everything in between...
ASP.NET • C# • HTML5 • JavaScript • AngularJs
Contact   •   Articles   •   Products   •   Support   •   Search
Ad-free experience sponsored by:
ASPOSE - the market leader of .NET and Java APIs for file formats – natively work with DOCX, XLSX, PPT, PDF, images and more

Building a SnagIt Screen Capture Plugin for Live Writer


I spent a few hours a couple of days ago creating a plugin for Windows Live Writer that allows for easy screen captures. I've long been a huge fan of SnagIt from Techsmith and since SnagIt's capture functionality is available as a COM interface it's quite easy to expose the functionality in other applications. For example, I have SnagIt plugged into my Help Builder tool to provide for screen captures in the Help HTML content.

Blogging is kind of similar: image capturing is pretty vital and making the process directly integrated into Live Writer itself makes screen captures a real cinch. Combined with Live Writer's ability to send images directly to the Web site via HTTP image capturing and publishing has never been easier.

You can grab the plug in and code from:
http://www.west-wind.com/tools/snagitlivewriterplugin.asp

Here's what the plugin looks like inside of Windows Live Writer:

SnagIt Screen Capture Plug in for Live Writer

When you click the Insert SnagIt button this dialog pops up which exposes most of the SnagIt capture options. Clicking Capture then goes off and uses SnagIt's native image capture functionailty (you know the red box to capture whatever capture mode selection you've made) to capture the image to file. You can optionally pop up the image editor and edit the image the same way as you can with native SnagIt use.

Settings are not saved, unless you click the Save Settings link, which stores the settings for later reuse. The idea is that you typically have a standard set of capture settings and these are restored each time you capture. You can also opt to not save the image locally. Live Writer actually makes a copy of each image you embed into a post so there's no need to hang on to captured images. The plugin writes out the file and then delay deletes the file if you have the Don't save image file option set to reduce file clutter on the local drive.

 

Creating a Live Writer Plugin

One of the nice things about Live Writer is the fact that you can very easily create plugins for it. You can download a Windows Live Writer SDK which provides fairly complete documentation and a few simple examples of how to plug into Live Writer. There are a host of different types of plugins you can create, although it looks like all plugins only address the content in the editor, not the overall operation of Writer. For example, as far as I can tell you can't override the HTTP communication or the actual messages that Writer sends when communicating with the server which would be very cool!

In any case creating an add-in that inserts content into the active blog post at the cursor position is very simple to create. The concept of this plug in is pretty simple:

  • Create a class library project
  • Add a reference to the WindowsLive.Writer.Api assembly to your project
  • Implement the PlugIn API and handle the CreateContent method
  • Create the SnagItAutomation object
  • Bring up the Configuration Dialog that configures the object
  • Run the screen capture
  • Retrieve the filename that the capture writes to disk
  • Insert the image as an <img> tag into the blog post

At the highest level the implementation of Writer Content plugin is quite simple:

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using WindowsLive.Writer.Api;
 
namespace SnagitScreenCapturePlugin
{
    [WriterPlugin( "7E113E74-A693-4bcd-8CF8-4C732654699C", 
        "SnagIt Screen Capture",        
         ImagePath = "Images.snagit.png",
         PublisherUrl = "http://www.west-wind.com/tools/SnagitLiveWriterPlugin.aspx",
         Description = "Embeds a screen capture image from SnagIt.")]
 
    [InsertableContentSource( "SnagIt Screen Capture" )]
    public class SnagitScreenCapturePlugin : ContentSource
    {
        public SnagitScreenCapturePlugin()
        {
        }
 
        public override DialogResult CreateContent(IWin32Window dialogOwner, ref string newContent)
        {        
            DialogResult dr = DialogResult.OK;
 
            // *** Result Output file captured
            string OutputFile = null;
 
            try
            {
                SnagItAutomation SnagIt = SnagItAutomation.Create();
                SnagIt.ActiveForm = Form.ActiveForm;
 
                SnagItConfigurationForm ConfigForm = new SnagItConfigurationForm(SnagIt);
                if (ConfigForm.ShowDialog() == DialogResult.Cancel)
                    return DialogResult.Cancel;
 
                OutputFile = SnagIt.CaptureImageToFile();
 
                SnagIt.SaveSettings();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to capture image:\r\n\r\n" + ex.Message,
                                "SnagIt Capture Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return DialogResult.Cancel;
            }
 
            // *** Just embed the image
            if (!string.IsNullOrEmpty(OutputFile))                    
                newContent = @"<img src='file:///" + OutputFile + "'>\r\n";
 
            return dr;
        }
 
 
    }
}

This is really all there's to the plugin portion of this particular plugin. All the work that happens for displaying the dialog and running the screen capture has really nothing to do with the plugin itself and is freestanding. The CreateContent method only cares about a result value that is the content HTML that is to be embedded into the page along with a DialogResult return value that indicates whether the operation was successful.

Posted in .NET  Live Writer  WebLog  

The Voices of Reason


 

Dan Neuman
March 19, 2007

# re: Building a SnagIt Screen Capture Plugin for Live Writer

Rick: Just curious what you use for a blogging service? Is it a part of WWWC5.X, or how did you add it to your site?

Rick Strahl
March 19, 2007

# re: Building a SnagIt Screen Capture Plugin for Live Writer

The blogging engine on this site is a custom ASP.NET application I built. But most services include support for MetaBlogApi which supports posting from generic tools like Live Writer. The blogging engine that comes with West Wind Web Connection is a more basic implementation and currently it doesn't have MetaWebLogApi support.


April 19, 2007

# Claudio Lassala in Software Development: Screen Capture

Claudio Lassala in Software Development: Screen Capture

Anon
April 21, 2007

# re: Building a SnagIt Screen Capture Plugin for Live Writer

Hi - doesn't work with Blogger. "Images cannot be published because the weblog does not support image publishing". One of those things I guess - but you might want to make that clear on your site before users download / install. Thx.

Rick Strahl
April 21, 2007

# re: Building a SnagIt Screen Capture Plugin for Live Writer

Eh, that's Live Writer's problem not the problem of the plug-in <s>... The plug in just creates the content - Live Writer's responsible for uploading the content to various blog engines.

I'm pretty sure Live Writer does work with Blogger though. You might have to switch to using MetaWebLog API in the configuration.

Laurent Duveau
April 28, 2007

# re: Building a SnagIt Screen Capture Plugin for Live Writer

Hi,
Great work Rick, I'll blog about this!
First time used I was stuck with an exception (Exception has been thrown by the target of an invocation). I finally found the cause : SnagIt was already running.

Also you made wrong copy/paste for property description, starting at "image cursor capture"... but not a big deal.

Thanks again for that.

# Customer Support - Integration with SnagIt


Jeff
November 08, 2007

# re: Building a SnagIt Screen Capture Plugin for Live Writer

I just discovered Windows Live Writer, and I'm loving it... Then I thought "Wow, it would be great if it worked with SnagIt... Then I discovered this!

It's great, and I'm not one to look a gift horse in the mouth, but I was wondering if you had given any thought to making a SnagIt "accessory" so one could launch SnagIt the usual way, and THEN dump the image into Live Writer. That would just kind of jive with my own workflow better. Maybe you know of someone who's already done this?

Li Yang
December 15, 2007

# re: Building a SnagIt Screen Capture Plugin for Live Writer

Thank God now TechSmith provides free licenses for SnagIt 7 so I can start to use it.

Mike Moore
December 02, 2008

# re: Building a SnagIt Screen Capture Plugin for Live Writer

I am attempting to ues your SnagIt capture plugin for WLW. However, after pressing the "capture" button an error message appears saying:

Failed to capture image:

SnagIt isn't installed - COM Access failed.
Please install SnagIt from Techsmith Corporation.

I am running SnagIt v9.0.2.

Any ideas as to how to correct this?

Thanks.

VC
October 22, 2013

# re: Building a SnagIt Screen Capture Plugin for Live Writer

Hi Rick,
Thanks for sharing these scripts. Just wanted to check if this solution works with Snagit V 11 ?

Thanks in advance,

VC

Rick Strahl
October 22, 2013

# re: Building a SnagIt Screen Capture Plugin for Live Writer

Yup works all the way up to SnagIt 11.

Berne
November 05, 2013

# re: Building a SnagIt Screen Capture Plugin for Live Writer

Hi, did you ever try to send keys to snagit to start a capture? I would like to use the COM interface, but I have 3 snagit profiles (activated using CTRL-1, 2 and 3) and I need to activate the correct one. the COM interface does not expose the profiles OR the associated printer setup.

Rick Strahl
November 05, 2013

# re: Building a SnagIt Screen Capture Plugin for Live Writer

@Berne - sorry no. The COM interface only allows explicit captures so you have to specify exactly what to capture. You might want to check with Techsmith's docs - they have updated the API over the years and actually documented it better.

http://download.techsmith.com/snagit/docs/comserver/enu/snagitcom.pdf
 

West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2017