Welcome Guest! To enable all features, please Login or Register.



Last Go to last post Unread Go to first unread post
#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.


Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

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

Groups: Registered, Tech Support, Administrators
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).


private void MakeSmooth(AnnPolylineObject obj) // Accepts a freehand annotation, since it's just a polyline
    LeadPointD[] points = obj.Points.ToArray();
    // Optional loop, repeating makes it smoother
    for (int i = 0; i < 4; i++)
        points = SmoothPoints(points);
    foreach (LeadPointD point in points)
private LeadPointD[] SmoothPoints(LeadPointD[] points, double factor = 0.25)
    LeadPointD[] result = new LeadPointD[points.Length * 2];
    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;
private LeadPointD Interpolate(LeadPointD from, LeadPointD to, double factor)
    // 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
LEAD Technologies, Inc.

You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.052 seconds.