gpt4 book ai didi

ios - CMFormatDescriptionRef 和 CMVideoFormatDescriptionGetDimensions

转载 作者:行者123 更新时间:2023-11-28 21:57:06 62 4
gpt4 key购买 nike

更新到 ios 8 后,我似乎无法获得 CMFormatDescriptionRefs Dimensions它总是返回 0,0 维。已经看过 apples 文档,但我真的不明白如何应用它。

这是我在 ios 7 上使用的现有代码(已经在我的 ios 7 设备上测试过了)

   NSArray *ports = [input ports];
AVCaptureInputPort *usePort = nil;
for ( AVCaptureInputPort *port in ports )
{
if ( usePort == nil || [port.mediaType isEqualToString:AVMediaTypeVideo] )
{

usePort = port;
break;
}
}

CMVideoFormatDescriptionRef format = [usePort formatDescription];
CMVideoDimensions dim = CMVideoFormatDescriptionGetDimensions(format);
cameraSize = CGSizeMake(dim.width, dim.height);

最佳答案

通过为 AVcapture 端口添加观察者解决了我的问题 formatDescription因为在 ios 8 版本中,使用获取端口格式描述的旧方法为您提供了一个“0”值。

第一行为AVCapture添加了一个观察者

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(avCaptureInputPortFormatDescriptionDidChangeNotification:)
name:AVCaptureInputPortFormatDescriptionDidChangeNotification object:nil];`

如果 AVCapture 发生变化,下一行将为您提供端口描述

- (void)avCaptureInputPortFormatDescriptionDidChangeNotification:(NSNotification *)notification {
[self initializeAPI];
NSArray *ports = [deviceInput ports];
AVCaptureInputPort *usePort = nil;
for ( AVCaptureInputPort *port in ports )
{
if ( usePort == nil || [port.mediaType isEqualToString:AVMediaTypeVideo] )
{

usePort = port;
break;
}
}

CMFormatDescriptionRef formatDescription = usePort.formatDescription;
if (formatDescription) {
CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions(formatDescription);
if ((dimensions.width == 0) || (dimensions.height == 0)) {


return;
}
CGFloat aspect = (CGFloat)dimensions.width / (CGFloat)dimensions.height;
BOOL is7x = floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1;
if (is7x) {
}else{
aspect = 1.f / aspect;

dimensionForIOS8Above = CGSizeMake(dimensions.width, dimensions.height);
//NSLog(@"8DIMENSION %f",dimensionForIOS8Above.width);



}



}

关于ios - CMFormatDescriptionRef 和 CMVideoFormatDescriptionGetDimensions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26175409/

62 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com