Click here to Skip to main content
15,867,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone

I need to change the ink color dynamically based on pressure value.

I was able to change the color, but if I apply more pressure on the stylus pen, the color remains constant and does not change as coded. Also if I lift the stylus and apply different amount of pressure the change is seen

I have written this code in the stylus move event

My code:

C#
private void StylusMoving(object sender, StylusEventArgs e)
        {
            StylusPointCollection stylusPoints = null;
            stylusPoints = e.GetStylusPoints(inkCanv);
            float currentPressure = stylusPoints[0].PressureFactor;
            txtPressure.Text = currentPressure.ToString();
           System.Windows.Ink.DrawingAttributes inkDA = new System.Windows.Ink.DrawingAttributes();
            inkDA.Height = 4;
            inkDA.Width = 4;
            inkDA.FitToCurve = false;
            int press = Convert.ToInt32(currentPressure * 100);
            if (press >= 0 && press <= 20)
            { inkDA.Color = Colors.Green; }
            else if (press >= 21 && press <= 40)
            { inkDA.Color = Colors.Orange; }
            else if (press >= 41 && press <= 60)
            { inkDA.Color = Colors.Blue; }
            else if (press >= 61 && press <= 80)
            { inkDA.Color = Colors.Red; }
            else if (press >= 81 && press <= 100)
            { inkDA.Color = Colors.Black; }
            else { inkDA.Color = Colors.Green; }

           inkCanv.DefaultDrawingAttributes = inkDA;

        }


Please help

Thanks in advance

Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900