2012-09-10 32 views
0

有一种方法可以通过程序获得用iPhone拍摄的照片的尺寸?我想直接把尺寸,而不经过throught模型版本,因此该方案不能有效:Iphone以编程方式获取照片分辨率

检查模型版本 - >写与每部iPhone模型的维度字典 - >采取正确的索引

回答

0

当你拍照时,你会得到一个UIImage。

UIImage对象有一个 - (CGSize)大小的方法,它返回图像的点的尺寸。你应该乘以它的scale属性来获取像素。

Source

普罗蒂普:阅读文档。

+0

将上述给予解决? –

+0

分辨率由像素高度的宽度(除以1M并四舍五入为小数点后第一位,以获得Mpixels) – Teejay

0

尝试为获得最大的分辨率的相机这段代码:

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