0

I'd like to create an app, which after clicking IBAction button should display current frame from live camera on UIImageView. Using this method: https://developer.apple.com/library/ios/qa/qa1702/_index.html
I'd like to create fuction in IBAction fuction. This one exactly:

- (void)captureOutput:(AVCaptureOutput *)captureOutput

Unfortunately after dozen of attempts I can't do it.

Summarizing: How to create a function (void), which contains image in UIImage form and save it to object in storyboard?

I'd be grateful for any help. Regards.

Nilesh
  • 701
  • 5
  • 14
Kejl
  • 53
  • 1
  • 1
  • 9
  • Why would you save to storyboard? Storyboard is a representation of "V" - View in MVC pattern. You should not "save" anything in view. – Nat Dec 16 '15 at 11:56
  • @Vive Okay, if you do not give what I could do to save a UIImage – Kejl Dec 16 '15 at 12:29

1 Answers1

0

Use this method to capture still images from AVCaptureSession where stillImageOutput is AVCaptureStillImageOutput:

[stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error)
{
    CVImageBufferRef imageBuffer =CMSampleBufferGetImageBuffer(imageSampleBuffer);
    CIImage *ciImage = [CIImage imageWithCVPixelBuffer:imageBuffer];
    CIContext *temporaryContext = [CIContext contextWithOptions:nil];
    CGImageRef videoImage =[temporaryContext
        createCGImage:ciImage
        fromRect:CGRectMake(
            0, 0,
            CVPixelBufferGetWidth(imageBuffer),
            CVPixelBufferGetHeight(imageBuffer)
        )];
    UIImage *image = [[UIImage alloc] initWithCGImage:videoImage];
    self.imageView.image = image;
}
rocambille
  • 15,398
  • 12
  • 50
  • 68
Shailesh
  • 51
  • 7