我正在尝试使用以下代码从我的 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];
}