2011-09-08 50 views
0

我捕捉使用如何從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

爲什麼它不起作用?我絕望...... 在此先感謝。

+0

如何在其他視圖控制器中訪問capturedImages? –

+0

foto.image = [capturedImages objectAtIndex:0];在另一個(photoView)視圖控制器的viewdidload方法 – Florian

回答

1
- (void) showPhoto:(UIImage*) bild 
{ 
    [session stopRunning]; 

    photoView.modalTransitionStyle = UIModalTransitionStyleCoverVertical; 
    [self presentModalViewController:photoView animated:YES]; 
    photoView.foto.image = (UIImage*)[capturedImages objectAtIndex:0]; 
} 
+0

謝謝你的工作!我添加了photoView.foto.image =(UIImage *)[photoView.capturedImages objectAtIndex:0];我不知道爲什麼,但它正在工作:) – Florian

+0

爲什麼我無法從photoView ViewController中的captureImages訪問數據? captureImages是photoView的一部分 – Florian

+0

新的很奇怪的問題... photoView.foto.image =(UIImage *)[capturedId objectEtIndex:0]; 這條線如上面所寫的那樣工作。 現在我想顯示3個框架。 我使用addFoto方法添加3個框架,然後我爲其他2張圖片使用相同的代碼。但只有第一個作品...奇怪的是,如果第一個是 photoView.foto2.image =(UIImage *)[photoView.capturedImages objectAtIndex:1]; 然後這一個工程...所以所有3張照片似乎是正確的photoView.capturedImages但第一次訪問後其他2不工作了... ... – Florian

相關問題