iPhoneで撮った写真の寸法をプログラムで取得する方法はありますか?モデルバージョンを通過せずに直接寸法を取得したいので、このソリューションは有効ではありません。
モデルのバージョンを確認する->各iphoneモデルの寸法を含む辞書を作成する->正しいインデックスを取得する
iPhoneで撮った写真の寸法をプログラムで取得する方法はありますか?モデルバージョンを通過せずに直接寸法を取得したいので、このソリューションは有効ではありません。
モデルのバージョンを確認する->各iphoneモデルの寸法を含む辞書を作成する->正しいインデックスを取得する
最大のカメラ解像度を取得するには、次のコードを試してください。
- (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);
}
写真を撮ると、UIImageが表示されます。
UIImageオブジェクトには、画像の寸法をポイントで返す-(CGSize)sizeメソッドがあります。ピクセルを取得するには、そのscaleプロパティを掛ける必要があります。
ProTip:ドキュメントを読んでください。