简体   繁体   中英

How to capture a single frame from iPhone4 camera and use it in other view?

I am capturing a single frame using

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection

Now I want to see this image on a different UIViewController which presents, but it doesn't work. I can display the taken image on the same UIViewController but on the other one it seems to be out of scope.

I tried it this way:

In captureOutput method:

CFRetain(sampleBuffer);
[photoView addFoto:sampleBuffer];
[self performSelectorOnMainThread:@selector(showPhoto:) withObject:nil waitUntilDone:YES];
CFRelease(sampleBuffer);

photoView is the other 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];
}

and in the viewDidLoad method of the photoView UIViewController:

- (void)viewDidLoad
{
    [super viewDidLoad];
    foto.image = [capturedImages objectAtIndex:0];
    // Do any additional setup after loading the view from its nib.
}

foto is the UIImageView

Why it doesn't work? I am desperate... Thanks in advance.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM