有一种方法可以通过编程方式获取使用iphone拍摄的照片尺寸吗?我想直接获取尺寸而不通过模型版本,因此该解决方案无效:
检查模型版本 - >写一个字典,其中包含每个iphone型号的尺寸 - >采取正确的指数
答案 0 :(得分:0)
当你拍照时,你会得到一个UIImage。
UIImage对象具有 - (CGSize)大小方法,该方法以点为单位返回图像的尺寸。你应该将它乘以它的scale属性来获得像素。
ProTip:阅读文档。
答案 1 :(得分: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);
}