3

有什么办法可以得到 iPhone 相机的分辨率?显然 3G 有 1200x1600,3GS 有 1500x2000,但是我如何从我的代码中获取这些值(不拍照)。我需要他们对相机预览进行一些仿射变换。

我可以检测硬编码这些值是 3G 还是 3GS,但这只是最后的手段。

4

6 回答 6

7

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

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

我投票支持模型检测。

于 2009-10-28T16:09:51.383 回答
3

这篇文章很旧,但它几乎是谷歌的第一个,而且它没有得到有效的答案,所以这里还有一个选择:

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);
    }

}
于 2012-08-15T16:26:37.300 回答
2

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

于 2009-11-19T17:32:15.140 回答
0

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

于 2009-10-28T16:23:10.140 回答
0

虽然我认为窃笑的答案绝对是正确的。我想我会为了好玩而发布这个。

您可以查看用户在 iPhone 上存储的相册(我大胆假设这可以在 iPhone 上无限制地以编程方式完成!!)假设手机上的照片大部分是用手机自己拍摄的,然后您就可以计算出平均照片分辨率并随之滚动。

于 2009-10-28T17:22:07.480 回答
0

你为什么不想拍照?使用 UIImagePickerController 的takePicture方法,告诉用户这是一个必要的校准步骤。之后,查看图片的分辨率,持续保存值,然后删除您拍摄的图片。之后,您将获得您的分辨率并能够在其上应用转换。

于 2009-10-29T09:02:34.900 回答