我捕捉使用如何從iPhone4相機捕捉單幀並在其他視圖中使用它?
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
現在我想看看在不同的UIViewController呈現, 這個圖像中的一個幀,但它不工作。我可以在同一個UIViewController上顯示拍攝的圖像,但在另一個上它看起來超出了範圍。
我嘗試了這種方式:
在captureOutput方法:
CFRetain(sampleBuffer);
[photoView addFoto:sampleBuffer];
[self performSelectorOnMainThread:@selector(showPhoto:) withObject:nil waitUntilDone:YES];
CFRelease(sampleBuffer);
PhotoView中是其它的UIViewController
- (void) addFoto:(CMSampleBufferRef) ref
{
UIImage *theImage = imageFromSampleBuffer(ref);
theImage = [[UIImage alloc] initWithCGImage:CGImageCreateCopy(theImage.CGImage)];
capturedImages = [NSMutableArray array];
[capturedImages addObject:theImage];
}
- (void) showPhoto:(UIImage*) bild
{
[session stopRunning];
photoView.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:photoView animated:YES];
}
並在PhotoView中的UIViewController viewDidLoad方法:
- (void)viewDidLoad
{
[super viewDidLoad];
foto.image = [capturedImages objectAtIndex:0];
// Do any additional setup after loading the view from its nib.
}
foto是UIImageView
爲什麼它不起作用?我絕望...... 在此先感謝。
如何在其他視圖控制器中訪問capturedImages? –
foto.image = [capturedImages objectAtIndex:0];在另一個(photoView)視圖控制器的viewdidload方法 – Florian