2010-11-12 161 views
-2

可能重複:
Access the camera with iPhone SDK如何在iPhone應用中截取屏幕截圖?

如何採取一個iPhone應用程序的照片?

我可以使用哪些API?

請提供的示例代碼。

+0

請在發佈新問題之前,搜索。這個問題是一個重複:HTTP://stackoverflow.com/questions/74113/access-the-camera-with-iphone-sdk – Moshe 2010-11-12 04:00:15

+0

截圖應用程序或相機的照片? – raidfive 2010-11-12 06:01:54

+0

重複:[使用iPhone SDK訪問相機](http://stackoverflow.com/questions/74113/access-the-camera-with-iphone-sdk) – Mario 2010-11-12 03:45:13

回答

2
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];