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];
    }
  • 相关阅读:
    Java中的IO操作和缓冲区
    Java是否还能再辉煌十年?
    Java的字符串操作
    WordCount(Java实现)
    自我介绍+软工5问
    数据库系统第六章【关系数据理论】(B站视频)
    ini 配置文件读取程序(C语言)
    epoll介绍 实例
    Blizzardhash算法oneway hash
    pychartdir模块安装
  • 原文地址:https://www.cnblogs.com/fengmin/p/5523100.html
Copyright © 2011-2022 走看看