0

iPhoneで撮った写真の寸法をプログラムで取得する方法はありますか?モデルバージョンを通過せずに直接寸法を取得したいので、このソリューションは有効ではありません。

モデルのバージョンを確認する->各iphoneモデルの寸法を含む辞書を作成する->正しいインデックスを取得する

4

2 に答える 2

1

最大のカメラ解像度を取得するには、次のコードを試してください。

- (CMVideoDimensions) getCameraMaxStillImageResolution:(AVCaptureDevicePosition) cameraPosition {

    CMVideoDimensions max_resolution;
    max_resolution.width = 0;
    max_resolution.height = 0;

    AVCaptureDevice *captureDevice = nil;

    NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
    for (AVCaptureDevice *device in devices) {
        if ([device position] == cameraPosition) {
            captureDevice = device;
            break;
        }
    }
    if (captureDevice == nil) {
        return max_resolution;
    }

    NSArray* availFormats=captureDevice.formats;

    for (AVCaptureDeviceFormat* format in availFormats) {
        CMVideoDimensions resolution = format.highResolutionStillImageDimensions;
        int w = resolution.width;
        int h = resolution.height;
        if ((w * h) > (max_resolution.width * max_resolution.height)) {
            max_resolution.width = w;
            max_resolution.height = h;
        }
    }

    return max_resolution;
}

- (void) printCamerasInfo {
    CMVideoDimensions res;
    res = [self getCameraMaxStillImageResolution:AVCaptureDevicePositionBack];
    NSLog(@" Back  Camera max Image resolution: %d x %d", res.width, res.height);
    res = [self getCameraMaxStillImageResolution:AVCaptureDevicePositionFront];
    NSLog(@" Front Camera max Image resolution: %d x %d", res.width, res.height);
}
于 2016-08-11T23:28:56.267 に答える
0

写真を撮ると、UIImageが表示されます。

UIImageオブジェクトには、画像の寸法をポイントで返す-(CGSize)sizeメソッドがあります。ピクセルを取得するには、そのscaleプロパティを掛ける必要があります。

ソース

ProTip:ドキュメントを読んでください。

于 2012-09-10T07:23:04.983 に答える