jharwig / PPSSignatureView

iOS Signature Capture Demo
MIT License
1.04k stars 234 forks source link

Example code for signature png image #14

Open jotterbot opened 9 years ago

jotterbot commented 9 years ago

Hello,

I am wondering if you could provide some example code in order to save the signature as a png.

I know that you have a method to do that in signatureImage but my problem is that I don't know how to get the signature to save, for example linking at the press of a button.

This is probably basic obj-c that I just don't understand. But if I use something like:

- (void)drawImage2
{    
    PPSSignatureView *sig = [[PPSSignatureView alloc]init];
    UIImage *image2 = [sig signatureImage];
    CGRect imageRect = CGRectMake(10, 10, 600, 600);
    [image2 drawInRect:imageRect];
}

I get a blank image 0 x 0 px. I guess i need to know how to target the existing signature in the GLKView.

Any help would be greatly appreciated.

Cheers!

sebromero commented 9 years ago

Your code looks basically ok to me. You would first want to setup a PPSSignatureView for example like this (untested):

- (void)viewDidLoad {
    [super viewDidLoad];
    PPSSignatureView* signatureView = [[PPSSignatureView alloc] initWithFrame:CGRectMake(10, 10, 600, 600)];
    [self.view addSubview:signatureView];
}

-(void)getSignature {
    PPSSignatureView* signatureView = self.view.subviews.firstObject;
    UIImage* signature = [signatureView signatureImage];
    //... e.g. save image to disk 
}