vigneshuvi / iOS-Signature-Capture

iOS-Signature-Capture is helps to capture the user signature with name and signed date in iOS and supports both Objective-c and Swift languages.
MIT License
52 stars 13 forks source link

How can i get points array? #3

Closed ismaiI1 closed 6 years ago

ismaiI1 commented 6 years ago

Hi,

I need to get array of points (x,y) from UIBezierPath in Obj-C. How can i get it?

ekran resmi 2017-12-06 14 10 40

vigneshuvi commented 6 years ago

After successfully saved signature, you can download it from NSUserDefaults.

    NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:USER_SIGNATURE_PATH];
    NSMutableArray *signPathArray = [NSKeyedUnarchiver unarchiveObjectWithData:data];

Get Path Array - Example

ismaiI1 commented 6 years ago

I can get Path array, but i need x and y coordinates of all points.

vigneshuvi commented 6 years ago

Find coordinates of path.

`-(void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [self becomeFirstResponder];

NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:USER_SIGNATURE_PATH];
NSMutableArray *signPathArray = [NSKeyedUnarchiver unarchiveObjectWithData:data];
[self.signatureView setPathArray:signPathArray];
[self.signatureView setNeedsDisplay];

for (UIBezierPath *path in signPathArray) {
    NSMutableArray *keyPoints = [NSMutableArray array];
    CGPathApply(path.CGPath, (__bridge void * _Nullable)(keyPoints), printPathXY);
}

}

void printPathXY (void info, const CGPathElement element) { CGPathElementType type = element->type; CGPoint point = *element->points; if (type != kCGPathElementCloseSubpath) { if ((type == kCGPathElementAddLineToPoint) || (type == kCGPathElementMoveToPoint)) NSLog(@"x:%f, y:%f",point.x, point.y); else if (type == kCGPathElementAddQuadCurveToPoint) NSLog(@"x:%f, y:%f",point.x, point.y); else if (type == kCGPathElementAddCurveToPoint) NSLog(@"x:%f, y:%f",point.x, point.y); } } `

vigneshuvi commented 6 years ago

Find coordinates of path:

-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self becomeFirstResponder];

    NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:USER_SIGNATURE_PATH];
    NSMutableArray *signPathArray = [NSKeyedUnarchiver unarchiveObjectWithData:data];
    [self.signatureView setPathArray:signPathArray];
    [self.signatureView setNeedsDisplay];

    for (UIBezierPath *path in signPathArray) {
        NSMutableArray *keyPoints = [NSMutableArray array];
        CGPathApply(path.CGPath, (__bridge void * _Nullable)(keyPoints), printPathXY);
    }
}

void printPathXY (void *info, const CGPathElement *element) {
    CGPathElementType type = element->type;
    CGPoint point = *element->points;
    if (type != kCGPathElementCloseSubpath)
    {
        if ((type == kCGPathElementAddLineToPoint) ||
            (type == kCGPathElementMoveToPoint))
                NSLog(@"x:%f, y:%f",point.x, point.y);
        else if (type == kCGPathElementAddQuadCurveToPoint)
            NSLog(@"x:%f, y:%f",point.x, point.y);
        else if (type == kCGPathElementAddCurveToPoint)
            NSLog(@"x:%f, y:%f",point.x, point.y);
    }
}
ismaiI1 commented 6 years ago

Thanks :) 👍