如何在iPhone应用中截取屏幕截图?
问题描述:
如何采取一个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];
请在发布新问题之前,搜索。这个问题是一个重复:HTTP://*.com/questions/74113/access-the-camera-with-iphone-sdk – Moshe 2010-11-12 04:00:15
截图应用程序或相机的照片? – raidfive 2010-11-12 06:01:54
重复:[使用iPhone SDK访问相机](http://*.com/questions/74113/access-the-camera-with-iphone-sdk) – Mario 2010-11-12 03:45:13