0

我正在尝试使用以下代码从我的 uiimagePickerController 截屏

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

它显示了除了从相机捕获的内容之外的所有内容,我看到了取消按钮,拍照按钮。而不是在相机上显示什么,而是在捕获黑屏,有什么办法可以解决这个问题吗?还是每隔 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];
}
4

1 回答 1

1

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

试试这个页面以获得一些信息:

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

于 2010-08-21T22:30:16.133 回答