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 属性以获取像素。

资源

专业提示:阅读文档。

于 2012-09-10T07:23:04.983 回答