Iphone get photo resolution programmatically

删除回忆录丶 提交于 2019-12-11 14:03:18

问题


There's a way to get programmatically the dimensions of a photo taken with an iphone? I want to take the dimensions directly without passing throught model version,so this solution can't be valid:

check model version->write a dictionary with dimensions of each iphone model -> take the correct index


回答1:


When you take a picture, you get an UIImage.

UIImage objects have a -(CGSize)size method that returns the dimensions of the image in points. You should multiply it by it's scale property to get pixels.

Source

ProTip: Read the documentation.




回答2:


Try this code for get maximum cameras resolution:

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


来源:https://stackoverflow.com/questions/12346943/iphone-get-photo-resolution-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!