Question

I want to create an app which detects a signature and store it in png format. I had find a link on how to draw http://www.ifans.com/forums/threads/tutorial-drawing-to-the-screen.132024/ . But i don't know how to save it as a png file. Can someone please help me on how to store an image drawn.

Was it helpful?

Solution

You can take a screenshot of the view and save that to the documents directory of your app.

Taking view screenshot,

CGRect rect = [yourView bounds];
UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
[yourView.layer renderInContext:context];   
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Saving the captured screenshot to documents directory,

NSString *documentsDirPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *pngFilePath = [NSString stringWithFormat:@"%@/myPngFile.png",documentsDirPath];
[UIImagePNGRepresentation(screenshot) writeToFile:pngFilePath atomically:YES];

Hope that helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top