com server examples - replace black color with white - vba excel 2010

  • 1
  • Question
  • Updated 5 years ago
as a kind of test to understand how i can change a color from a captured active window to a other color, i'll have a Excel userform with a black background and would like to change it in white.
here's the code i have so far (VBA EXCEL 2010):

Sub StartHere()
'original userform backcolor = &H8000000F&
'see also:

Dim strMsg As String
Dim wshShell As Object

Dim objSnagit As SNAGITLib.IImageCapture     'ImageCapture As SNAGITLib.IImageCapture
Dim ImageFilters As SNAGITLib.ImageFilters
Dim ColorSub As SNAGITLib.IImageColorSubstitution

' Check command line arguments (none required)
' Capture input type
Const siiDesktop = 0
Const siiWindow = 1
Const siiRegion = 4
Const siiGraphicFile = 6
Const siiClipboard = 7
Const siiDOSScreen = 8
Const siiMenu = 9
Const siiObject = 10
Const siiProgramFile = 11
Const siiFreehand = 12
Const siiEllipse = 13
Const siiRoundedRect = 14
Const siiTriangle = 15
Const siiPolygon = 16
Const siiWallpaper = 17
Const siiCustomScroll = 18
Const siiTWAIN = 19
Const siiDirectX = 20
Const siiExtendedWindow = 23

' Window selection method
Const swsmInteractive = 0
Const swsmActive = 1
Const swsmHandle = 2
Const swsmPoint = 3

' Capture output type
Const sioPrinter = 1
Const sioFile = 2
Const sioClipboard = 4
Const sioMail = 8
Const sioFTP = 32

' Output image type
Const siftBMP = 0
Const siftPCX = 1
Const siftTIFF = 2
Const siftJPEG = 3
Const siftGIF = 4
Const siftPNG = 5
Const siftTGA = 6

' Output color depth
Const sicdAuto = 0
Const sicd1Bit = 1
Const sicd2Bit = 2
Const sicd3Bit = 3
Const sicd4Bit = 4
Const sicd5Bit = 5
Const sicd6Bit = 6
Const sicd7Bit = 7
Const sicd8Bit = 8
Const sicd16Bit = 16
Const sicd24Bit = 24
Const sicd32Bit = 32

' Output file naming method
Const sofnmPrompt = 0
Const sofnmFixed = 1
Const sofnmAuto = 2

' Create the required objects
Set wshShell = CreateObject("WScript.Shell")
' SnagIt objects
Set objSnagit = CreateObject("SNAGIT.ImageCapture.1")
Set ImageFilters = objSnagit.Filters
Set ColorSub = ImageFilters.ColorSubstitution

' Set input options
    With objSnagit
        .Input = siiWindow              'get the active window
        .inputwindowoptions.selectionmethod = swsmActive
        .IncludeCursor = False     'True
' Set output options
        .Output = sioFile
        .OutputImageFile.FileType = siftPNG
        .OutputImageFile.ColorDepth = sicd32Bit
        .OutputImageFile.FileNamingMethod = sofnmFixed
        .OutputImageFile.Filename = "snagtest"
        .OutputImageFile.Directory = "C:\"
' Capture
End With

'Set custom color substitution
ColorSub.ColorSubMethod = scsmCustom

'Define color subs
Call ColorSub.ClearColorSub

'replace black color with white
Call ColorSub.AddColorSub(RGB(0, 0, 0), RGB(255, 255, 255), 100, False)

' Launch the captured image in the default viewer
wshShell.Run "C:\snagtest.png", 0, False

' Release the objects
Set objSnagit = Nothing
Set wshShell = Nothing
End Sub
question now is, why is the black color not replaced with white?

any help welcome
Photo of Ludo Soete

Ludo Soete

  • 5 Posts
  • 0 Reply Likes

Posted 5 years ago

  • 1
Photo of Rick Stone

Rick Stone

  • 5920 Posts
  • 2823 Reply Likes
I'm not sure I understand what you are asking here. You want one of us to tell you how to modify the code? That's certainly not something you would do using SnagIt, At least as far as I'm aware.

For me, I'd capture the window, then click the paint can, set the color and flood fill the black with white.

Cheers... Rick :)
Photo of Ludo Soete

Ludo Soete

  • 5 Posts
  • 0 Reply Likes
Hi Rick,
Thanks for the reply.

As you know, SnagIt can be programmed using the COM server objects and their properties.
The whole idea behind it is to automate as much as possible, preventing errors, gain speed and getting always the same result.
The userform provided in the main message is just for a test. 
Actually, i'll have a active window (form) capture with on the left side a chart and on the right side a few check boxes, see pictures below.
The chart background is black with thin colored lines. if i print it the lines aren't good visible on the black background, and it use a lot of toner too.
That's why i like to get the possibility to change colors (AND select only a part of the activewindow AND add some text on the remaining 'picture').
I printed the whole COM server document (11.1), but it realy lacks on usefull examples on how to use the different objects & properties.

So Yes, any help on how i need to write code to automate SnagIt is welcome.
There's not much code on the internet too, so, if TechSmith could add basic examples in their COM Server document on how to use it, i'll would appreciate it.
Microsoft isn't also a verry good teacher with it's examples, but it gives you a idea on how to use it. 

Here below you'll see the real screen dump and the latter picture is aprox. what i need.

Best regards,
Photo of Rick Stone

Rick Stone

  • 5917 Posts
  • 2823 Reply Likes
Nope, I did not know one could go that far with SnagIt and actually feed it code that way. That's a totally new one on me. And it's so far above my own pay scale that I'll have to leave it to the SnagIt development team or another poster with these coding skills to answer.

My real world analogy here is that I most definitely DO NOT want to know how the sausage is made. I just want to eat it. ;)

Have fun! Rick :)
Photo of Joe Morgan

Joe Morgan

  • 7558 Posts
  • 4138 Reply Likes
There is a simple way to do color replacement through a custom profile.
The problem with that?  Color replacement is applied to the entire Image leaving you with the image I have uploaded below. I used your Analyzer example.
I can't think of a way to streamline a capture with color replacement being restricted to only a portion of a capture. You could restrict your capture to just the graph but the Scale numbers turn white also.  


I would get in contact with Tech support and see what they say. Sorry I couldn't help further.

This is a free service!

Just fill out a SUPPORT TICKET at.


 Or you could Give the Tech Support Team a call at 888.750.0686 (or +1.517.381.2300 ext. 771 internationally)--they are available from 8 am - 7 pm EST.

Regards, Joe...    {:> )

Photo of Ludo Soete

Ludo Soete

  • 5 Posts
  • 0 Reply Likes
Hi Joe,
Thanks for your reply.
I could generate the same result as yours by opening the screendump with Iview (Irfan).
Would be great if color could be replaced in a defined area and not the whole picture.
If i can't find a solution soon, i'll give up on it and continue by copy/ paste/ add text/ invert color in MS PAINT (manually).
If it wasn't of the verry UNDOCUMENTED COM Server documentation, i could be much further on the idea i have.
I'm not the only one who isn't pleased with the actual COM Server document (11.1). :(

anyhow, thanks a lot for everyone who contributed on my message.

Best regards,
Photo of Stacy

Stacy, Employee

  • 52 Posts
  • 8 Reply Likes
Hi Ludo,

I was able to reproduce the problem with color sub not working using the script that you pasted at the top of this thread. The problem is with this line:
'Set custom color substitution
ColorSub.ColorSubMethod = scsmCustom

scsmCustom is not defined and ColorSubMethod is being assigned the value of zero, which translates to scsmNone. You need to define scsmCustom as a const having the value of 2.

Please let me know if you need to see my modifications to your script above :)
- stacy
Photo of Stacy

Stacy, Employee

  • 52 Posts
  • 8 Reply Likes
Um, you are right about the samples no longer being available. We used to have them in a zip that you can download from the same page that the COM documentation was on. I will see if we can get those added back. For now, place some old Snagit 10 COM samples that you can download here:
Sorry, but those are the most recent ones that I could find :( Hopefully we can get some updated samples back on our website soon. Thank you for bringing this to our attention.

Photo of Ludo Soete

Ludo Soete

  • 5 Posts
  • 0 Reply Likes
Hi Stacy,
Thanks for your replies.

Managed it to make the changes you mentioned in your first reply.

added following constants:
'custom color sub enumeration
Const scmNone = 0
Const scsmInvert = 1
Const scsmCustom = 2

'Snag Trim Method enumerations
Const stmNone = 0
Const stmManual = 1
Const stmAuto = 2

Concerning your second reply, i would like to see more examples on how to set a reference and use of the different objects and their properties.
There's almost nothing to find on the internet on how to use the Com Server libraries, objects & properties.
TechSmith works close with Microsoft, so take a look on how they provide small examples on how to use the objects & properties.

I would like to know (example) how i can add text programatically to a picture, and capture only a part of the original picture.

Let's use the code from my first message, with the addes constants as mentioned in this message.

Now, i added following code lines (VBA Excel 2010)

Dim AddMyText As SNAGITLib.ImageAnnotation 'add custom text to the image
Dim TrimImage As SNAGITLib.ImageTrim 'select only a part of the image 

Now, i need to set a reference to the AddMyText &  TrimImage  object, so i can use it and it's properties.
Here's my problem: What should be placed in the ?????? location?

Set AddMyText = ???????
Set TrimImage = ???????

'add custom text to image
With AddMyText
    .EnableCaption = True
    .CaptionOptions.Font.Height = 18
    .CaptionText = "Test Only"
End With

'trim image
        With TrimImage
            .Bottom = 100
            .Left = 100
            .Right = 100
            .Top = 100
            .TrimMethod = stmManual
        End With

So, that's 2 of the examples that can be added into the Com Server document. :)
Examples makes coding a lot easier for programmers than let them spend hours or day's to find out how it works.

I notice also in the code following

'Set custom color substitution 
ColorSub.ColorSubMethod = scsmCustom 
'Define color subs 
Call ColorSub.ClearColorSub 
Call ColorSub.AddColorSub(RGB(255, 255, 255), RGB(247, 247, 247), 100, False) 
Call ColorSub.AddColorSub(RGB(74, 73, 74), RGB(255, 255, 255), 100, False) 
Call ColorSub.AddColorSub(RGB(0, 0, 0), RGB(255, 255, 255), 100, False) 

see original message :

Why the need to use Call?
I expected following to work, but it doesn't:

'Set custom color substitution
        With ColorSub
            .ColorSubMethod = scsmCustom
            .AddColorSub(RGB(0, 0, 0), RGB(255, 255, 255), 100, False)
        End With

Any help and examples are welcome.

Best regards,
Photo of Stacy

Stacy, Employee

  • 52 Posts
  • 8 Reply Likes
Hi Ludo,

Sorry for not getting back to you. I did not get an email notifying me that this thread was updated. Strange.. Anyhow, I wanted to thank you for your input and also let you know that we moved our COM samples to Git Hub. We updated the documentation (though I know it is not how you suggested - maybe in time ) and added a few new samples. There is a comprehensive image capture example (but it is in C#) that shows how to use pretty much all of the COM interfaces exposed by Snagit. You can access the samples directly from Git Hub or from our enterprise page .

Thanks again for your support.

This conversation is no longer open for comments or replies.