【问题标题】:How do I take a screenshot in iPhone app? [duplicate]如何在 iPhone 应用程序中截取屏幕截图? [复制]
【发布时间】:2011-05-08 20:44:57
【问题描述】:

可能重复:
Access the camera with iPhone SDK

如何在 iPhone 应用中拍照?

我可以使用哪个 API?

请提供示例代码。

【问题讨论】:

标签: iphone objective-c camera


【解决方案1】:
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];

【讨论】:

    猜你喜欢
    • 2011-03-18
    • 2011-05-28
    • 2013-11-26
    • 1970-01-01
    • 2012-01-12
    • 1970-01-01
    • 1970-01-01
    • 2011-08-14
    • 1970-01-01
    相关资源
    最近更新 更多