How to Programmatically Take Photos While Recordin

2020-02-10 08:29发布

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.

4条回答
▲ chillily
2楼-- · 2020-02-10 09:04

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

查看更多
老娘就宠你
3楼-- · 2020-02-10 09:16

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.

查看更多
家丑人穷心不美
4楼-- · 2020-02-10 09:23

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:

查看更多
我命由我不由天
5楼-- · 2020-02-10 09:25

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

查看更多
登录 后发表回答