zoukankan      html  css  js  c++  java
  • AVCaptureSession 照相时获取 AVCaptureVideoPreviewLayer尺寸

    http://stackoverflow.com/questions/14153878/avcapturesession-preset-photo-and-avcapturevideopreviewlayer-size


    I initialize an AVCaptureSession and I preset it like this :

    AVCaptureSession *newCaptureSession = [[AVCaptureSession alloc] init];
    if (YES==[newCaptureSession canSetSessionPreset:AVCaptureSessionPresetPhoto]) {
        newCaptureSession.sessionPreset = AVCaptureSessionPresetPhoto;
    } else {
        // Error management
    }

    Then I setup an AVCaptureVideoPreviewLayer :

    self.preview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height/*426*/)];
    CALayer *previewLayer = preview.layer;
    AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.session];
    captureVideoPreviewLayer.frame = previewLayer.frame;
    [previewLayer addSublayer:captureVideoPreviewLayer];
    captureVideoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspect;

    My question is:
    How can I get the exact CGSize needed to display all the captureVideoPreviewLayer layer on screen ? More precisely I need the height as AVLayerVideoGravityResizeAspect make the AVCaptureVideoPreviewLayer fits the preview.size ?
    I try to get AVCaptureVideoPreviewLayer size that fit right.

    Very thank you for your help
    objective-c ios camera
    share|improve this question
        

        

    After some research with AVCaptureSessionPresetPhoto the AVCaptureVideoPreviewLayer respect the 3/4 ration of iPhone camera. So it's easy to have the right height with simple calculus.
    As an instance if the width is 320 the adequate height is:
    320*4/3=426.6
    share|improve this answer








    // Get your AVCaptureSession somehow. I'm getting mine out of self.videoCamera, which is a GPUImageVideoCamera
        // Get the appropriate AVCaptureVideoDataOutput out of the capture session. I only have one session, so it's easy.

        AVCaptureVideoDataOutput *output = [[[self.videoCamera captureSession] outputs] lastObject];
        NSDictionary* outputSettings = [output videoSettings];

        // AVVideoWidthKey and AVVideoHeightKey did not work. I had to use these literal keys.
        long width  = [[outputSettings objectForKey:@"Width"]  longValue];
        long height = [[outputSettings objectForKey:@"Height"] longValue];

        // video camera output dimensions are always for landscape mode. Transpose if your camera is in portrait mode.
        if (UIInterfaceOrientationIsPortrait([self.videoCamera outputImageOrientation])) {
            long buf = width;
            width = height;
            height = buf;
        }

        CGSize outputSize = CGSizeMake(width, height);

  • 相关阅读:
    三元表达式 列表和字典推导式 函数对象 名称空间 作用域 global和nonlocal 函数装饰器 枚举对象
    函数参数 打散机制 字符串比较 返回值
    函数简介
    三种字符串的介绍 文件的读写
    字符编码
    数据类型及其常用方法 数据类型转换 可变与不可变 值拷贝与深浅拷贝
    流程控制 while和for循环
    变量命名规范 常量 输入和输出 注释 数据类型 运算符 逻辑运算符
    语言分类 编译型和解释型语言分析 环境变量 代码执行的方式 pip介绍 变量
    Python django tests
  • 原文地址:https://www.cnblogs.com/allanliu/p/4173257.html
Copyright © 2011-2022 走看看