2012-09-10 2 views
0

아이폰으로 찍은 사진의 크기를 프로그래밍 방식으로 얻을 수있는 방법이 있습니까? 나는 축복하는 모델 버전을 거치지 않고 직접 치수를 먹고 싶어, 그래서이 솔루션은 유효하지 않을 수 있습니다아이폰은 프로그래밍 방식으로 사진 해상도를 얻습니다.

체크 모델 버전 -> 각 아이폰 모델의 크기로 사전 쓰기 -> 올바른 인덱스

답변

0

을 사진을 찍으면 UIImage가 생깁니다.

UIImage 개체에는 이미지의 크기를 포인트 단위로 반환하는 - (CGSize) size 메서드가 있습니다. 픽셀을 얻으려면 크기 속성을 곱해야합니다.

Source

ProTip : 설명서를 참조하십시오.

+0

을 위주고 해상도 것? –

+0

해상도는 높이 단위의 너비 (픽셀 단위)로 주어지며 (1M 단위로 나눠서 1 번째 소수점 이하로 반올림하여 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); 
} 
관련 문제