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);
AVCaptureSession 照相时获取 AVCaptureVideoPreviewLayer尺寸的更多相关文章
- ios或者cocos2d-x开发在Xcode编译时自适应失效,获取屏幕尺寸不准确
在cocos2d-x的开发中,发现之前很好使的 setDesignResolutionSize(960.0f, 640.0f, kResolutionExactFit)自适应不好用了,后来调试发现不是 ...
- Android计量单位px,in,mm,pt,dp,dip,sp和获取屏幕尺寸与密度
###########################################Android计量单位########################################### px ...
- iOS根据Url 获取图片尺寸
iOS根据Url 获取图片尺寸 // 根据图片url获取图片尺寸 +(CGSize)getImageSizeWithURL:(id)imageURL { NSURL* URL = nil; if([i ...
- (转载)iOS UILabel自定义行间距时获取高度
本文介绍一下自定义行间距的UILabel的高度如何获取,需要借助一下开源的UILabel控件:TTTAttributedLabel 附下载地址 https://github.com/TTTAttrib ...
- 根据Url 获取图片尺寸 iOS
// 根据图片url获取图片尺寸 +(CGSize)getImageSizeWithURL:(id)imageURL { NSURL* URL = nil; if([imageURL ...
- iOS开发——运行时OC篇&使用运行时获取系统的属性:使用自己的手势修改系统自带的手势
使用运行时获取系统的属性:使用自己的手势修改系统自带的手势 有的时候我需要实现一个功能,但是没有想到很好的方法或者想到了方法只是那个方法实现起来太麻烦,一或者确实为了装逼,我们就会想到iOS开发中最牛 ...
- 工具类 dp转px 获取图片实际尺寸 获取屏幕尺寸
dp转px public class Dp2pxUtils { public static int Dp2Px(Context context, float dp) { final float sca ...
- iOS UILabel自定义行间距时获取高度
本文介绍一下自定义行间距的UILabel的高度如何获取,需要借助一下开源的UILabel控件:TTTAttributedLabel 附下载地址 https://github.com/TTTAttrib ...
- iOS开发——根据Url 获取图片尺寸
转自:http://www.oschina.net/code/snippet_2248391_53038 // 根据图片url获取图片尺寸 +(CGSize)getImageSizeWithURL:( ...
随机推荐
- WIFI环境下Android手机和电脑通信
前面已经写过一篇java实现最基础的socket网络通信,这篇和之前那篇大同小异,只是将客户端代码移植到手机中,然后获取本机IP的方法略有不同. 先讲一下本篇中用到Android studio的使用吧 ...
- UVa 10305 (拓扑排序) Ordering Tasks
题意: 经典的拓扑排序.有n个任务,然后某些任务必须安排在某些任务前面完成,输出一种满足要求的序列. 分析: 拓扑排序用离散里面的话来说就是将偏序关系拓展为全序关系.我们将“小于”这种关系看做一条有向 ...
- <pages validateRequest="false"/>在.net4.0中无效的问题
再web.config中设置<pages validateRequest="false"/>在.net4.0中无效的问题 解决方案: <system.web> ...
- ionic preparing for ios 9
http://blog.ionic.io/preparing-for-ios-9/ Preparing for iOS 9 Tweet By Max on September 12, 2015 i ...
- C扩展Python
基本想法: 先看中文小介绍,再看英文详细文档. 1. 参考 首先参考THIS, IBM的工程师好像出了好多这样的文章啊,而且每次看到时间戳,我都想戳自己- -! 2. ERROR 可能遇到错误: fa ...
- noip2006提高组题解
第一题:能量项链 区间型动态规划 据说这题在当年坑了很多人. f(i, j) 表示从第i个珠子开始合并j个珠子所释放的最大能量. f(i, j) = max{ f(i, k} + f(i+k, j-k ...
- 【MySQL】Java对SQL时间类型的操作(获得当前、昨天、前年。。时间)
Java获得当前时间 java.util.Date date = new java.util.Date(); Timestamp time = new Timestamp(date.getTime() ...
- 常用的PL/SQL开发原则
(1)广泛使用绑定变量,特别是批量绑定,因为这可以有效的避免sql的硬解析和PL/SQL引擎和SQL引擎的上下文切换!(2)广泛使用UROWID来处理DML语句(UROWID是ROWID扩展,ORAC ...
- Asp.Net MVC4 系列-- 进阶篇之路由(1)【转】
http://blog.csdn.net/lan_liang/article/details/22993839?utm_source=tuicool
- Andorid-Fragment生命周期
官网帮助文档链接: http://developer.android.com/guide/components/fragments.html Fragment的生命周期: Fragment与Activ ...