Dev Corner - Camtasia Studio and Cursor Effects
Posted on Thursday May 19, 2011 by Betsy Weber

It's Thursday and that means it's time for Dev Corner! This week, Randall Brown and Jared Wein chat with A.J. Orians about Camtasia Studio. Any suggestions for next week's Dev Corner topic? What do you want to know from our Developers?
Andrew "A.J." Orians is a developer on the Windows version of Camtasia Studio. Though he enjoys programming he also likes puzzles, running, games, and a whole slew of other activities. He has been at TechSmith for something like five years and looks forward to being here for many more!
There are some really cool features in Camtasia Studio 7; my personal favorite is Cursor Effects. The spotlight effect and the ability to change the highlight effect post-recording is very cool! For these features to work you need your recording to be a Camrec (Camtasia Studio Recording document) from Camtasia Studio 7 or later:

For all the AVI files recorded over the years and all the Camrec files from earlier versions of Camtasia Studio they do not have cursor information attached and so Cursor Effects cannot be used with these files. So I worked on a program which goes through each frame of a video and tries to locate the cursor and so this program will create cursor information such that you could use the spotlight effect or add a highlight effect! The program takes as input either a Camrec or an AVI and produces a Camrec with cursor data.
The program basically starts at the beginning of the video and goes through each frame to the end and tries to locate one of the cursor images somewhere in the frame. To speed up the process I break up the frame into a grid and so I locate the cursor in one frame then in the next frame I first search for a cursor in a subsection of the whole frame, the same grid location. If I do not find it within that grid location I try the search in the surrounding grid areas before finally searching across the whole frame.
In source code, this process looks like the following:
public IEnumerable NextRectangleOfInterest(Point ptPosition)
{
//First look at the rectangle which has the point
int nRow = -1;
int nCol = -1;
if (ptPosition != Point.Empty)
{
GetSectionWithPoint(ptPosition, ref nRow, ref nCol);
yield return GetRectangleAt(nRow, nCol);
//Next look at surrounding rows/columns
if (nRow > 0)
yield return GetRectangleAt(nRow - 1, nCol);
if (nCol > 0)
yield return GetRectangleAt(nRow, nCol-1);
if (nRow < m_Sections.Count - 1)
yield return GetRectangleAt(nRow + 1, nCol);
if (nCol < m_Sections[0].Count-1)
yield return GetRectangleAt(nRow, nCol+1);
//Upper left
if (nRow > 0 && nCol > 0)
yield return GetRectangleAt(nRow-1, nCol - 1);
//Upper right
if (nRow > 0 && nCol < m_Sections[0].Count - 1)
yield return GetRectangleAt(nRow - 1, nCol + 1);
//lower left
if (nRow < m_Sections.Count - 1 && nCol > 0)
yield return GetRectangleAt(nRow + 1, nCol - 1);
//lower right
if (nRow < m_Sections.Count - 1 && nCol < m_Sections[0].Count - 1)
yield return GetRectangleAt(nRow + 1, nCol + 1);
}
for (int Row = 0; Row < m_Sections.Count; Row++)
{
for (int Col = 0; Col < m_Sections[Row].Count; Col++)
{
if (ptPosition != Point.Empty)
{
if (Math.Abs(nRow - Row) <= 1 || Math.Abs(nCol - Col) <= 1)
continue;
}
yield return GetRectangleAt(Row, Col);
}
}
yield break;
}
Since the cursor is visible in the video; having the Cursor Effects option "Mouse cursor visible" checked will have two cursors displayed (hopefully directly on top of each other). Also this program doesn't work with animated cursors or the I-beam cursor. Nonetheless if you use the Recorder in Camtasia Studio 7 you will not hit any of these issues! The preferred route is to use Recorder in Camtasia Studio 7; this program was meant both for learning as well as creating something that might be useful.

