iOS开发自定义相机(拍照,录制视频)

使用AVFoundation框架,

这里是Demo

首先声明以下对象:

#import "CustomeCameraViewController.h"
#import <AVFoundation/AVFoundation.h>
#import <AssetsLibrary/AssetsLibrary.h>

@interface CustomeCameraViewController ()<AVCaptureFileOutputRecordingDelegate>

{
    // AVCaptureSession对象来执行输入设备和输出设备之间的数据传递
    AVCaptureSession *iSession;
    //当前设备
    AVCaptureDevice *iDevice;
    //输入设备
    AVCaptureDeviceInput *iDeviceInput;
    //照片输出流
    AVCaptureStillImageOutput *iStillImageOutput;
    //预览图层
    AVCaptureVideoPreviewLayer *iPreviewLayer;
    
}
初始化各对象:

- (void)viewDidLoad {
    [super viewDidLoad];
   
    //点击屏幕对焦
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(focusTap:)];
    [self.view addGestureRecognizer:tap];
    
    
    iSession = [[AVCaptureSession alloc]init];
    
    NSArray *deviceArray = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
    for (AVCaptureDevice *device in deviceArray) {
        
        //AVCaptureDevicePositionBack 后置摄像头
        //AVCaptureDevicePositionFront 前置摄像头
        if (device.position == AVCaptureDevicePositionBack) {
            iDevice = device;
        }
    }
    
    
    iSession.sessionPreset = [self getSessionPresetForDevice:iDevice];
    
    iDeviceInput = [[AVCaptureDeviceInput alloc]initWithDevice:iDevice error:nil];
    
    
    输出设置。AVVideoCodecJPEG   输出jpeg格式图片
    iStillImageOutput = [[AVCaptureStillImageOutput alloc]init];
    NSDictionary *outputDic = [NSDictionary dictionaryWith
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值