2010-08-21 107 views
0

我尝试使用下面的代码来获取屏幕快照从我的UIImagePickerControlleriPhone - UIImagePickerController采取屏幕截图?

UIGraphicsBeginImageContext(imagePicker.view.bounds.size); 
[self.imagePicker.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

它显示了一切,除了什么是从相机拍摄,我看到了取消按钮,拍照BUTTOM。 而不是在相机上显示它捕捉黑屏,有没有办法解决这个问题?或者更好的方法每隔1秒自动从相机捕捉图像?

- (void)captureOutput:(AVCaptureOutput *)captureOutput 
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer 
     fromConnection:(AVCaptureConnection *)connection 
{ 
    UIImage *image = [self imageFromSampleBuffer:sampleBuffer]; 
    UIImageView *img = [[UIImageView alloc] initWithImage:image]; 
    [img setFrame:CGRectMake(0, 0, 320, 480)]; 
    [self.view addSubview:img]; 
    [img release]; 
} 

回答

1

您想使用新的(在OS 4中)AVFoundation API。

试试这个页面的一些信息:

http://developer.apple.com/iphone/library/qa/qa2010/qa1702.html

+0

感谢,这似乎是最好的办法,但远远Ø我接收到的数据无法转换到一个UIImage。我会更新 – aryaxt 2010-08-21 23:53:43

+0

我发布的链接中的示例代码应该有所帮助。部分向下是一行,它说<使用图像在这里添加您的代码>。在这一点上,你有一个喜欢做你喜欢的事情。 – 2010-08-21 23:59:28

+0

是的一切工作正常,我收到captureOutput,但是当我将它转换为uiimage并创建一个imageview并将其添加到我的观点,uiimageview不显示图片,我想不知何故数据被中断。这是否设想在iphone 3g上工作?因为iphone 3g不允许录像。 – aryaxt 2010-08-22 00:23:46