Error

# Freehand Annotation from Windows Ink - Freehand Annotation from Windows Ink

#1 Posted : Thursday, December 14, 2017 9:49:30 AM(UTC)

Groups: Registered
Posts: 13

I have a function that current captures windows ink into a freehand annotation and we save it to a bitmap.
Is there any way to manipulate this annotation to smooth out the resulting image? I would like to adjust the result to include variable line width in response to inking pressure data.

Thanks.

#2 Posted : Thursday, December 14, 2017 2:19:05 PM(UTC)

Posts: 199

Was thanked: 28 time(s) in 28 post(s)

Hello Andy,

There are a variety of smoothing algorithms you can use, I don't believe we have any built in however. One that is fairly simple to implement is Chaikin's Algorithm. I'll put a snippet below for a basic implementation of this. The only issue is we don't support setting the thickness of line segments individually, you can only set the line width of the entire polyline (the freehand annotation).

Code:

private void MakeSmooth(AnnPolylineObject obj) // Accepts a freehand annotation, since it's just a polyline
{
// Optional loop, repeating makes it smoother
for (int i = 0; i < 4; i++)
points = SmoothPoints(points);
obj.Points.Clear();
}
{
int index = 0;

// Retain start
result[index++] = points[0];

// Smooth each point
for (int i = 0; i < points.Length; i++)
{
if (i != 0) // Add previous
result[index++] = Interpolate(points[i], points[i - 1], factor);
if (i != points.Length - 1) // Add next
result[index++] = Interpolate(points[i], points[i + 1], factor);
}

// Retain end
result[index++] = points[points.Length - 1];

return result;
}
{
// Basic linear interpolation between two points
return LeadPointD.Create(from.X + (to.X - from.X) * factor, from.Y + (to.Y - from.Y) * factor);
}

If you want to interpolate with some weighting, it might be best to create your own custom Point class that contains a position and a weight, then modify the Interpolate function to also account for weighting. As I mentioned before, the only issue I see you having is our annotations don't allow variable thickness within a single annotation, you would need to create a bunch of single line annotations. I can create a modification to this program with those requirements if you'd like, but this should be a good starting point.

EDIT: The original implementatin of Chaikin's Algorithm doesn't retain the endpoints, which results in the shape getting shorter. I assumed you wouldn't want this effect, so I kept the endpoints.
Anthony Northrup
Developer Support Engineer