IOS摄像,载图总结

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





http://blog.csdn.net/mangosnow/article/details/37745205


创建自定义的媒体捕捉方案


AVCaptureSession  控制来自一个输入设备的声音和视频,流入一个输出缓冲区AVCaptureOutput的过程
1. 创建AVCaptureSession
2. 设置会话的录音、录音质量的预置值
3. 添加必要的输入捕捉设备 通过AVCaptureDevice来创建,可以是一个摄像头、麦克风、诸如此类
4. 添加必要的数据输出缓冲区 AVCaptureStillImageOutput 或者 AVCaptureVideoDataOutput
5. 启动AVCaptureSession
    
AVCaptureVideoPreviewLayer

自定义图片步骤方案

[objc] view plaincopyprint?CODE_ico.png


  1. <span style="font-size:14px;">-(void)setupAVCapture{  
  2.    // 步骤  
  3.    // 1) 设置 capture session  
  4.    // 2) 设置 capture device  
  5.    // 3) 设置 capture device input  
  6.    // ----  
  7.    // 配置 Capture Session  
  8.    // ----  
  9.    // 4) 添加 device input  capture session  
  10.    // 5) 创建 still image output, 并添加到 capture session  
  11.    // 6) 创建 video output, a并添加到 capture session  
  12.    // ----  
  13.    // 设置 video preview layer  
  14.    // ----  
  15.    // 7) 根据 capture session 创建 Video Preview layer  
  16.    // ----  
  17.    // 完成设置  
  18.    // ----  
  19.    // 8) 提交 session 配置  
  20.    // 9) 开始运行 capture session  
  21.     
  22.     
  23.    // 1) 设置 capture session  
  24.    // ========================================  
  25.    capSession = [[AVCaptureSession alloc] init];  
  26.     
  27.    [capSession setSessionPreset:AVCaptureSessionPresetMedium];  
  28.   
  29.    // 2) 设置 capture device  
  30.    // ========================================  
  31.    AVCaptureDevice *capDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];  
  32.     
  33.     
  34.    // 3) 设置 capture device input  
  35.    // ========================================  
  36.    NSError *error = nil;  
  37.    AVCaptureDeviceInput *capDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:capDevice error:&error];  
  38.    if(error!=nil){  
  39.        NSLog(@"There was an error setting up capture input device:\n%@",[error localizedDescription]);  
  40.        [self destroyAVCapture];  
  41.    }  
  42.    else{  
  43.        [capSession beginConfiguration];  
  44.   
  45.        self.isUsingFrontFacingCamera = NO;  
  46.        self.isCapturingVideo = NO;  
  47.         
  48.        // 4) 添加 device input  capture session  
  49.        // ========================================  
  50.        if([capSession canAddInput:capDeviceInput])  
  51.            [capSession addInput:capDeviceInput];  
  52.        else  
  53.            NSLog(@"could not add input");  
  54.         
  55.        
  56.        // 5) 创建 still image output, 并添加到 capture session  
  57.        // ========================================  
  58.   
  59.        stillImageOutput = [AVCaptureStillImageOutput new];  
  60.        [stillImageOutput addObserver:self  
  61.                                forKeyPath:@"capturingStillImage"  
  62.                                   options:NSKeyValueObservingOptionNew  
  63.                                   context:@"AVCaptureStillImageIsCapturingStillImageContext"];  
  64.         
  65.        if([capSession canAddOutput:stillImageOutput])  
  66.            [capSession addOutput:stillImageOutput];  
  67.         
  68.         
  69.         
  70.        // 6) 创建 video output, a并添加到 capture session  
  71.        // ========================================  
  72.         
  73.        videoDataOutput = [AVCaptureVideoDataOutput new];  
  74.   
  75.        NSDictionary *rgbOutputSettings = [NSDictionary dictionaryWithObject:  
  76.                                           [NSNumber numberWithInt:kCMPixelFormat_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey];  
  77.        [videoDataOutput setVideoSettings:rgbOutputSettings];  
  78.         
  79.        [videoDataOutput setAlwaysDiscardsLateVideoFrames:YES];  
  80.                 
  81.        // create a serial dispatch queue used for the sample buffer delegate as well as when a still image is captured  
  82.        // a serial dispatch queue must be used to guarantee that video frames will be delivered in order  
  83.        // see the header doc for setSampleBufferDelegate:queue: for more information  
  84.        videoDataOutputQueue = dispatch_queue_create("VideoDataOutputQueue", DISPATCH_QUEUE_SERIAL);  
  85.        [videoDataOutput setSampleBufferDelegate:self queue:videoDataOutputQueue];  
  86.        
  87.        if([capSession canAddOutput:videoDataOutput])  
  88.            [capSession addOutput:videoDataOutput];  
  89.        else  
  90.            NSLog(@"Could not add output");  
  91.   
  92.   
  93.        // 7) 根据 capture session 创建 Video Preview layer  
  94.        // ========================================  
  95.         
  96.        // 设置 video preview layer  
  97.        videoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:capSession];  
  98.        videoPreviewLayer.frame = videoPreview.bounds;  
  99.        videoPreviewLayer.backgroundColor = [UIColor blackColor].CGColor;  
  100.        videoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;  
  101.         
  102.        videoPreview.layer.masksToBounds = YES;  
  103.        [videoPreview.layer addSublayer:videoPreviewLayer];  
  104.         
  105.         
  106.        // 8) 提交 session 配置  
  107.        // 9) 开始运行 capture session  
  108.        // ========================================  
  109.        [capSession commitConfiguration];  
  110.        [capSession startRunning];  
  111.         
  112.   
  113.        //Make sure video is not recording  
  114.        [[videoDataOutput connectionWithMediaType:AVMediaTypeVideo] setEnabled:NO];  
  115.   
  116.   
  117.    }  
  118. </span>  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值