3

Is there any way to get the resolution of the iPhone's camera? Apparently the 3G has 1200x1600, and 3GS has 1500x2000, but how do I obtain these values from inside my code (without taking the picture). I need them to make some affine transform to the camera preview.

I could detect if it's 3G or 3GS to hardcode these values, but it's just the last resort.

4

6 に答える 6

7

あなたの「最後の手段」は良い解決策だと思います。

モデルの検出の何が問題になっていますか? ハードウェアはこれらのモデルのどちらでも変更されません.. 唯一の懸念は、3GSX-R または何かが 16mpx カメラを搭載するかどうかです。その時点で、とにかくアプリを更新する必要があり、リストに別の値を追加するだけで済みます。

私はモデル検出に投票します。

于 2009-10-28T16:09:51.383 に答える
3

投稿は古いですが、Google でほぼ最初のものであり、有効な回答がないため、もう 1 つのオプションがあります。

4.x から 7.x までの iOS 向けのソリューション

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向けソリューション

Apple は再びすべてを変更しました: 今すぐ購読する必要があります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

While I think snicker's answer is definitely the correct one. I thought I'd post this for fun.

You could look through the users stored photo album on the iPhone (I am making a bold assumption that this can be done programatically on the iPhone without restrictions!!) making the assumption that the photos on the phone were mostly taken with the phone it's self, you could then work out what the average photo resolution is and roll with that.

于 2009-10-28T17:22:07.480 に答える
0

写真を撮りたくないのはなぜですか?UIImagePickerController のtakePictureメソッドを使用して、これが必要なキャリブレーション手順であることをユーザーに指示します。その後、写真の解像度を見て、値を永続的に保存し、撮影した写真を削除します。その後、解決策が得られ、変換を適用できるようになります。

于 2009-10-29T09:02:34.900 に答える
0

Apple はハードウェアと直接通信できないため、正規の App Store 製品を選択する選択肢はほとんどありません。

于 2009-10-28T16:23:10.140 に答える