如何在iPhone应用程序中截图?

如何在iPhone应用程序中截图?,iphone,objective-c,camera,Iphone,Objective C,Camera,可能重复: 如何在iPhone应用程序中拍照 我可以使用哪种API 请提供示例代码。副本:请在发布新问题之前搜索。这个问题是重复的:应用程序的屏幕截图还是相机照片? UIGraphicsBeginImageContext(self.view.bounds.size); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *saveImage = UIGraphicsGetImageFromCurre

可能重复:

如何在iPhone应用程序中拍照

我可以使用哪种API


请提供示例代码。

副本:请在发布新问题之前搜索。这个问题是重复的:应用程序的屏幕截图还是相机照片?
UIGraphicsBeginImageContext(self.view.bounds.size);

[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *saveImage = UIGraphicsGetImageFromCurrentImageContext();   
CGContextRef context = UIGraphicsGetCurrentContext();

UIImageWriteToSavedPhotosAlbum(saveImage, self, @selector(image:didFinishSavingWithError:contextInfo:), &context);
UIGraphicsEndImageContext();

// saving image in documents folder
NSData *imageData = UIImagePNGRepresentation(saveImage);
NSString *imageName = @"temp.png";

NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];

NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:imageName];
[imageData writeToFile:fullPathToFile atomically:NO];