iOS提供了两种拍照的方法:
1.通过UIImagePickerController的方式进行拍摄。
2.通过 AV Foundation framework 提供的接口进行拍摄。
https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/CameraAndPhotoLib_TopicsForIOS/Introduction/Introduction.html#//apple_ref/doc/uid/TP40010405-SW1
Taking Pictures and Movies
截图 如何使用UIImagePickerController 方法拍照
https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/CameraAndPhotoLib_TopicsForIOS/Articles/TakingPicturesAndMovies.html#//apple_ref/doc/uid/TP40010406-SW1
UIKit Framework Reference 所有UIKit Framework的接口文档
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIKit_Framework/index.html#classes
UIImagePickerController的详细接口内容 Available in iOS 2.0 and later.
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImagePickerController_Class/index.html
About AV Foundation 介绍AV Foundation的架构 (AV Foundation Programming Guide)
https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/00_Introduction.html#//apple_ref/doc/uid/TP40010188
AV Foundation Framework Reference 所有AV Foundation的接口文档
https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVFoundationFramework/index.html#classes
Media Capture and Access to Camera
Recording input from cameras and microphones is managed by a capture session. A capture session coordinates the flow of data from input devices to outputs such as a movie file. You can configure multiple inputs and outputs for a single session, even when the session is running. You send messages to the session to start and stop data flow.
In addition, you can use an instance of a preview layer to show the user what a camera is recording.
详细介绍 av foundation 如何拍照
截图
https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/04_MediaCapture.html#//apple_ref/doc/uid/TP40010188-CH5-SW2
其他:
AV Foundation is available in iOS 4.0 and later, and OS X 10.7 and later
IOS8 新增功能点:
https://developer.apple.com/library/ios/releasenotes/General/WhatsNewIniOS/Articles/iOS8.html#//apple_ref/doc/uid/TP40014205-SW1
Manual Camera Controls:
The AV Foundation framework (AVFoundation.framework) makes it easier than ever to take great photos. Your app can take direct control over the camera focus, white balance, and exposure settings. In addition, your app can use bracketed exposure captures to automatically capture images with different exposure settings.
Improved Camera Functionality
Use the following APIs to discover and enable new camera features found on the iPhone 6 and iPhone 6 Plus:
A new property (videoHDRSupported) can determine whether a capture device supports high dynamic range streaming.
A new video stabilization mode (AVCaptureVideoStabilizationModeCinematic) provides more cinematic results in the captured video.
A new property (highResolutionStillImageOutputEnabled) can be used to set an AVCaptureStillImageOutput object to capture still pictures at a higher resolution.
A new property (autoFocusSystem) can be used to determine how the camera performs auto focusing.
IOS8的代码变化。其中重点关注avfoundation的几个class变化。
https://developer.apple.com/library/ios/releasenotes/General/iOS80APIDiffs/frameworks/AVFoundation.html
What's New in iOS 每个IOS版本的发布内容变化
https://developer.apple.com/library/ios/releasenotes/General/WhatsNewIniOS/Introduction/Introduction.html#//apple_ref/doc/uid/TP40008244-SW1
IOS摄像,载图总结
1 建立Session
2 添加 input
3 添加output
4 开始捕捉
5 为用户显示当前录制状态
6 捕捉
7 结束捕捉
8 参考
https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/04_MediaCapture.html#//apple_ref/doc/uid/TP40010188-CH5-SW2
AVCaptureSession
AVCaptureVideoPreviewLayer
AVCaptureDevice
AVCaptureDeviceInput
AVCaptureStillImageOutput
AVCaptureConnection
- Create an AVCaptureSession object to coordinate the flow of data from an AV input device to an output
- Find the AVCaptureDevice object for the input type you want
- Create an AVCaptureDeviceInput object for the device
- Create an AVCaptureVideoDataOutput object to produce video frames
- Implement a delegate for theAVCaptureVideoDataOutput object to process video frames
- Implement a function to convert the CMSampleBuffer received by the delegate into a UIImage object
http://blog.csdn.net/mangosnow/article/details/37745205
创建自定义的媒体捕捉方案
AVCaptureSession 控制来自一个输入设备的声音和视频,流入一个输出缓冲区AVCaptureOutput的过程
1. 创建AVCaptureSession
2. 设置会话的录音、录音质量的预置值
3. 添加必要的输入捕捉设备 通过AVCaptureDevice来创建,可以是一个摄像头、麦克风、诸如此类
4. 添加必要的数据输出缓冲区 如AVCaptureStillImageOutput 或者 AVCaptureVideoDataOutput
5. 启动AVCaptureSession
AVCaptureVideoPreviewLayer
自定义图片步骤方案
- <span style="font-size:14px;">-(void)setupAVCapture{
- // 步骤
- // 1) 设置 capture session
- // 2) 设置 capture device
- // 3) 设置 capture device input
- // ----
- // 配置 Capture Session
- // ----
- // 4) 添加 device input 到 capture session
- // 5) 创建 still image output, 并添加到 capture session
- // 6) 创建 video output, a并添加到 capture session
- // ----
- // 设置 video preview layer
- // ----
- // 7) 根据 capture session 创建 Video Preview layer
- // ----
- // 完成设置
- // ----
- // 8) 提交 session 配置
- // 9) 开始运行 capture session
- // 1) 设置 capture session
- // ========================================
- capSession = [[AVCaptureSession alloc] init];
- [capSession setSessionPreset:AVCaptureSessionPresetMedium];
- // 2) 设置 capture device
- // ========================================
- AVCaptureDevice *capDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
- // 3) 设置 capture device input
- // ========================================
- NSError *error = nil;
- AVCaptureDeviceInput *capDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:capDevice error:&error];
- if(error!=nil){
- NSLog(@"There was an error setting up capture input device:\n%@",[error localizedDescription]);
- [self destroyAVCapture];
- }
- else{
- [capSession beginConfiguration];
- self.isUsingFrontFacingCamera = NO;
- self.isCapturingVideo = NO;
- // 4) 添加 device input 到 capture session
- // ========================================
- if([capSession canAddInput:capDeviceInput])
- [capSession addInput:capDeviceInput];
- else
- NSLog(@"could not add input");
- // 5) 创建 still image output, 并添加到 capture session
- // ========================================
- stillImageOutput = [AVCaptureStillImageOutput new];
- [stillImageOutput addObserver:self
- forKeyPath:@"capturingStillImage"
- options:NSKeyValueObservingOptionNew
- context:@"AVCaptureStillImageIsCapturingStillImageContext"];
- if([capSession canAddOutput:stillImageOutput])
- [capSession addOutput:stillImageOutput];
- // 6) 创建 video output, a并添加到 capture session
- // ========================================
- videoDataOutput = [AVCaptureVideoDataOutput new];
- NSDictionary *rgbOutputSettings = [NSDictionary dictionaryWithObject:
- [NSNumber numberWithInt:kCMPixelFormat_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey];
- [videoDataOutput setVideoSettings:rgbOutputSettings];
- [videoDataOutput setAlwaysDiscardsLateVideoFrames:YES];
- // create a serial dispatch queue used for the sample buffer delegate as well as when a still image is captured
- // a serial dispatch queue must be used to guarantee that video frames will be delivered in order
- // see the header doc for setSampleBufferDelegate:queue: for more information
- videoDataOutputQueue = dispatch_queue_create("VideoDataOutputQueue", DISPATCH_QUEUE_SERIAL);
- [videoDataOutput setSampleBufferDelegate:self queue:videoDataOutputQueue];
- if([capSession canAddOutput:videoDataOutput])
- [capSession addOutput:videoDataOutput];
- else
- NSLog(@"Could not add output");
- // 7) 根据 capture session 创建 Video Preview layer
- // ========================================
- // 设置 video preview layer
- videoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:capSession];
- videoPreviewLayer.frame = videoPreview.bounds;
- videoPreviewLayer.backgroundColor = [UIColor blackColor].CGColor;
- videoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
- videoPreview.layer.masksToBounds = YES;
- [videoPreview.layer addSublayer:videoPreviewLayer];
- // 8) 提交 session 配置
- // 9) 开始运行 capture session
- // ========================================
- [capSession commitConfiguration];
- [capSession startRunning];
- //Make sure video is not recording
- [[videoDataOutput connectionWithMediaType:AVMediaTypeVideo] setEnabled:NO];
- }
- </span>