繁体   English   中英

获得iPhone的相机分辨率?

[英]Get iPhone's camera resolution?

有没有办法获得iPhone相机的分辨率? 显然3G的分辨率为1200x1600,而3GS的分辨率为1500x2000,但是如何从代码内部获取这些值(无需拍照)。 我需要他们对相机预览进行仿射变换。

我可以检测是对这些值进行硬编码的3G还是3GS,但这只是最后的选择。

我认为您的“最后一招”是一个很好的解决方案。

检测模型有什么问题? 这些型号的硬件都不会改变。您可能唯一担心的是3GSX-R或16mpx相机附带的东西。 在这一点上,您可能仍然必须更新您的应用程序,并且可以将另一个值添加到列表中。

我投票支持模型检测。

该帖子很旧,但是它几乎是谷歌中的第一篇,并且没有有效的答案,因此这里还有一个选择:

适用于iOS从4.x到7.x的解决方案

一切都取决于AV Foundation框架

配置并启动AVCaptureSession之后,您可以在[[[session.inputs.lastObject] ports].lastObject formatDescription]变量中找到视频尺寸

这是大概的代码:

AVCaptureSession* session = ...;
AVCaptureDevice *videoCaptureDevice = ...;
AVCaptureDeviceInput *videoInput = ...;

[session beginConfiguration];
if ([session canAddInput:videoInput]) {[session addInput:videoInput];}
[session commitConfiguration];
[session startRunning];

//this is the clue
AVCaptureInputPort *port = videoInput.ports.lastObject;
if ([port mediaType] == AVMediaTypeVideo)
{
    videoDimensions = CMVideoFormatDescriptionGetDimensions([port formatDescription]);
}

iOS8解决方案

苹果确实再次改变了一切:现在您必须订阅AVCaptureInputPortFormatDescriptionDidChangeNotification

这是示例:

-(void)initSession
{
    AVCaptureSession* session = ...;
    AVCaptureDevice *videoCaptureDevice = ...;
    AVCaptureDeviceInput *videoInput = ...;

    [session beginConfiguration];
    if ([session canAddInput:videoInput]) {[session addInput:videoInput];}
    [session commitConfiguration];
    [session startRunning];

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

-(void)avCaptureInputPortFormatDescriptionDidChangeNotification:(NSNotification *)notification
{
    AVCaptureInputPort *port = [videoInput.ports objectAtIndex:0];
    CMFormatDescriptionRef formatDescription = port.formatDescription;
    if (formatDescription) {
        videoDimensions = CMVideoFormatDescriptionGetDimensions(formatDescription);
    }

}

您真的需要知道图像的分辨率来设置仿射变换吗? 由于视图是预先设置的,可以覆盖屏幕的整个宽度,因此您可以根据要占据的屏幕部分来更改变换,即,如果您需要预览的像素为160像素,只需将其缩小默认值的50%。 我现在正在应用程序中执行此操作,并且它可以在新旧iPhone上使用...

由于Apple不允许您直接与硬件对话,因此对于合法的App Store产品确实没有太多选择。

虽然我认为窃笑的答案肯定是正确的。 我以为我会发布这个有趣的。

您可以浏览存储在iPhone上的用户相册(我做出了一个大胆的假设,即可以无限制地在iPhone上以编程方式完成此操作!),并假设手机上的照片大部分是用手机本身拍摄的,然后可以计算出平均照片分辨率,然后进行滚动。

你为什么不想拍照? 使用UIImagePickerController的takePicture方法,指示用户这是必要的校准步骤。 之后,查看照片的分辨率,永久保存该值,然后删除拍摄的照片。 之后,您将拥有自己的分辨率,并将能够在其上应用变换。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM