4

The iPhone 5S is capable of taking pictures while recording video and I am trying to figure out how I would do this programatically. I know I would be utilizing AVFoundation, however, I couldn't find anything in the programming guide regarding this. I have also checked the sample projects (AVFoundation-related) and it doesn't look like there is anything there that does what I am looking for. if you could help point me in the right direction that would be great.

Stunner
  • 12,025
  • 12
  • 86
  • 145
  • means you want capture photo from video (like video cover image) ?? – Mitul Bhadeshiya Apr 08 '14 at 05:37
  • No, thanks for asking. On the iPhone 5S in the camera app, when doing a video recording, you may take pictures (by tapping a white button off to the side). I want to achieve this sort of thing in my app, programatically. I will even go so far to consider private APIs. – Stunner Apr 08 '14 at 06:07

4 Answers4

6

Actually you can do it with any device that can record video:

  • Create and configure a AVCaptureVideoDataOutput.
  • Add it to your AVCaptureSession.
  • Add a AVCaptureVideoDataOutputSampleBufferDelegate.
  • Implement captureOutput:didOutputSampleBuffer:fromConnection: in the delegate and get the image with imageFromSampleBuffer:.

Some similar code can be found here, where images are captured at a given interval, but you only want one image.

Rivera
  • 10,792
  • 3
  • 58
  • 102
3

In iOS7 there has a new api to capture UIView, we can get image and do something.

eg:

UIView+Screenshot.h
-(UIImage *)convertViewToImage;

UIView+Screenshot.m

-(UIImage *)convertViewToImage
{
    UIGraphicsBeginImageContext(self.bounds.size);
    [self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return image;
}

Apple's Document: drawViewHierarchyInRect:afterScreenUpdates:

eason
  • 2,854
  • 3
  • 16
  • 18
1

Through AVCaptureSession you can easily achieve iPhone 5S in the camera app functionality. In your view touch event:

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

You can get current frame on above delegate method and save it in your gallery.

Please go through below link:

https://developer.apple.com/library/ios/samplecode/RosyWriter/Introduction/Intro.html

Lundin
  • 195,001
  • 40
  • 254
  • 396
Rahul Juyal
  • 2,124
  • 1
  • 16
  • 33
0

I agree with Rivera's answer ! You are going to need AV

And this is how I do it after the hole AV stuff

CGImageRef bigImage = image.CGImage;
CGRect rectImage = CGRectMake(self.scannArea.origin.x*widhtRatio,
                              self.scannArea.origin.y*heightRatio - 50,
                              self.scannArea.size.width*widhtRatio,
                              self.scannArea.size.height*heightRatio);
CGImageRef part = CGImageCreateWithImageInRect(bigImage, rectImage);
UIImageWriteToSavedPhotosAlbum([UIImage imageWithCGImage:part], nil, nil, nil);

image = [self drawImage:[UIImage imageNamed:@"overlaygraphic.png"] 
                inImage:image 
                atPoint:CGPointMake(self.scannArea.origin.x*widhtRatio, 
                                    self.scannArea.origin.y*heightRatio - 50)];
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);

if you want to see the hole sample np. I will upload my class

jpjacobs
  • 9,359
  • 36
  • 45
Mingebag
  • 748
  • 2
  • 20
  • 35