Detect touch shape on iphone or android?

Is there an open or closed API that would allow the application to get the surface that has been affected? I'm interested in Android and / or iOS.

In other words, I'm interested in the shape of the finger that touched the screen.

A solution that returns a matrix of the affected rectangles will also be fine.

(I'm 90% sure that there is no such thing, but I hope someone can prove that I'm wrong)

+4
source share
3 answers

Response to the request:
On Android, I should think that it is best to use MotionEvent.getSize () , which returns the size of the finger (not a shape though). TouchPaint API Demo uses this.

+3
source

This code is an idea on how to get the affected rectangles. For each new rectangle that touches the counter, 1 will be added, so it’s easier to track the movement of the touch (if necessary). For greater accuracy, change the values ​​of the constants ROWS and COLS

#define ROWS 15 #define COLS ROWS int matrix[ROWS][COLS]; int squareCounter; - (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject]; CGPoint location = [touch locationInView:touch.view]; int col = floor((location.x * COLS) / self.view.frame.size.width); int row = floor((location.y * ROWS) / self.view.frame.size.height); if (matrix[col][row] == 0) matrix [col][row] = ++ squareCounter; [label setText:[NSString stringWithFormat:@"[%d][%d] -> %d", col, row, matrix[col][row]]]; } - (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { NSString *matrixStr = @""; for (int i = 0; i < COLS; i++) { for (int j = 0; j < ROWS; j++) { matrixStr = [matrixStr stringByAppendingFormat:@"%d\t", matrix[j][i]]; } matrixStr = [matrixStr stringByAppendingString:@"\n"]; } NSLog(@"Matrix:\n%@", matrixStr); } - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { squareCounter = 0; for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { matrix[i][j] = 0; } } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } 

It must be placed on the view controller whose presentation you want to determine the shape of the touch.

+1
source

I found a solution for Android: https://stackoverflow.com/questions/8977510/motionevent-pointercoords-gettouchmajor-device-support . I still need to figure out how much this is supported, but ...

And for the iPhone: Is there any way that I can tell how hard the screen will be pressed (see accepted answer). However, there seems to be no official way.

However, I would appreciate if someone added some formal or informal / hacker methods.

+1
source

Source: https://habr.com/ru/post/1389902/


All Articles