how to recognise character drawn on canvas
Asked Answered
S

1

6

i am using finger paint to draw line,and So far I have come up with the following code:

 case MotionEvent.ACTION_MOVE:
    //return if touch is in this area of canvas
    if (x<=430 || y<=80 || y>=490) return true;
    //draw path using x and y co-ordinates
    mPath.quadTo(previousPoint.x, previousPoint.y, (x+previousPoint.x)/2,(y+previousPoint.y)/2);
    canvas.drawPath(mPath, paint);
    previousPoint.x = x;
    previousPoint.y = y;
    //invalidate canvas on move
    imageView.invalidate();
    break;
case MotionEvent.ACTION_UP:
    Xend=x;
    Yend=y;
    //validate that is it true?
    if((Xstart>=780 && Xstart<=830) && (Xend>=780 && Xend<=830) && (Ystart>=10 && Ystart<=200) && Yend<=800 && Yend>=300){
    //show toast if correct
    Toast.makeText(getBaseContext(), "Correct", Toast.LENGTH_SHORT).show();
    }else{
    //show toast with XY co-ordinates that your attempt is wrong 
    Toast.makeText(getBaseContext(), "Wrong attempt\n Xstart: "+Xstart+"\n Xend:"+Xend+"\n Ystart: "+Ystart+"\nYend:"+Yend, Toast.LENGTH_SHORT).show();
    }
    imageView.invalidate();
    break;

But unfortunately, the above code does not fulfill my requirements. I want to create alphabetically organized worksheets, through which the user proceeds by touch. I'd like to know where he started, where he is moving to and where he ended to recognize what he drawn on canvas, i know where to get touch points but the problem is how to recognise what has been drawn on canvas? wants to recognize like this VisionObjects app on playstore. enter image description here

Sora answered 3/1, 2013 at 6:1 Comment(4)
If you are in doubt about something in android first try looking for a sample app in the apis demos...it's a good place to start. There is a very good example here for handling touch in android. This is the path ..\android-sdk-windows\samples\android-10\ApiDemos\src\com\example\android\apis\graphics\FingerPaint.javaBra
What's the point of the above code (did you write that yourself?), if it has nothing to do with your requirements? I also have issues understanding the actual question: Do you simply want to track touch-motions? Such as the user touches the screen (start), moves his finger 5cm to the left (moving) and then let's go (end)?Sternforemost
yes zainodis you are right,that's my requirement.i want to know finger movement,i want to track it.Sora
See #15988203 for an example of how to track (and draw in a canvas) the movement of the user's finger.Markland
A
0

To track the three events you have to use:

  • MotionEvent.ACTION_DOWN to track where the event started.
  • MotionEvent.ACTION_MOVE to track the movements (swipe).
  • MotionEvent.ACTION_UP to track where the event stopped.

See this example. In shows how to draw a path by tracking the movements.

Amain answered 27/9, 2013 at 8:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.