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];
    }
  • 相关阅读:
    几种常用的曲线
    0188. Best Time to Buy and Sell Stock IV (H)
    0074. Search a 2D Matrix (M)
    0189. Rotate Array (E)
    0148. Sort List (M)
    0859. Buddy Strings (E)
    0316. Remove Duplicate Letters (M)
    0452. Minimum Number of Arrows to Burst Balloons (M)
    0449. Serialize and Deserialize BST (M)
    0704. Binary Search (E)
  • 原文地址:https://www.cnblogs.com/fengmin/p/5523100.html
Copyright © 2011-2022 走看看