zoukankan      html  css  js  c++  java
  • 使用AVCaptureSession显示相机预览

    #import <UIKit/UIKit.h>
    #import <AVFoundation/AVFoundation.h>
    @interface ViewController : UIViewController
    @property (nonatomic,strong) AVCaptureSession * captureSession;
    @property (nonatomic,strong) AVCaptureDeviceInput * videoInput;
    
    @end
    - (void)viewDidLoad {
        [super viewDidLoad];
        self.captureSession = [[AVCaptureSession alloc] init];
        self.captureSession.sessionPreset = AVCaptureSessionPresetHigh;
        AVCaptureDevice * device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
        NSError * error = nil;
        self.videoInput = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
        if (self.videoInput) {
            [self.captureSession addInput:self.videoInput];
        }else{
            NSLog(@"Input Error:%@",error);
        }
        AVCaptureVideoPreviewLayer * previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:self.captureSession];
        UIView * aView = self.view;
        previewLayer.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-70);
        [aView.layer addSublayer:previewLayer];
    }
    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
        [self.captureSession startRunning];
    }
    
    - (void)viewDidDisappear:(BOOL)animated
    {
        [super viewDidDisappear:animated];
        [self.captureSession stopRunning];
    }
  • 相关阅读:
    第3章 MFC框架程序剖析
    第2章 掌握C++
    第1章 Windows程序内部运行机制
    【MFC】画线
    使用RegSetValueEx修改注册表时遇到的问题(转)
    读书笔记
    POJ 1182[并查集]
    读书笔记
    HihoCoder 1532 : 最美和弦
    HihoCode 1531 : 德国心脏病
  • 原文地址:https://www.cnblogs.com/fengmin/p/5523100.html
Copyright © 2011-2022 走看看