determining ios camera aspect ratio

6k views Asked by At

I was wondering if anyone knew of a way to get the aspect ratio of an iOS camera BEFORE a picture is taken. I've done some reading and it seems the a 4/3 aspect ratio is pretty common on the devices but was not sure if that was true for all devices or what the deal was. I know you can figure it out after taking a picture but I am looking for a way to determine it before doing that.

Thank you

EDIT:

Judging by the responses I've gotten so far I think I need to clarify my question. The aspect ratio of the iOS camera is a physical property of the camera that is independent of the orientation a picture is taken in. Does anyone know how to get this ratio before/without taking a picture.

3

There are 3 answers

1
GridIron On

You could try fetching the last photo in the camera roll and see what its aspect ratio is.

This assumes: 1) your app has camera roll access 2) the last photo was actually taken on the current device

0
Ten On

for swift

let sizeCamera = CMVideoFormatDescriptionGetPresentationDimensions(backCamera.activeFormat.formatDescription, usePixelAspectRatio: true, useCleanAperture: true);
1
prewett On

As of iOS 7 you can get the dimensions of video/camera:

CGSize size = CMVideoFormatDescriptionGetPresentationDimensions(camera.activeFormat.formatDescription, YES, YES);

Where camera is the AVCaptureDevice* object for the camera.

There is also CMVideoFormatDescriptionGetDimensions(). Unfortunately, this doesn't seem to be the same as the camera images. On my iPhone 4S (iOS 7), ...GetDimensions() returns 1920x1080, which does not seem to be the same dimensions returned from AVCaptureStillImageOutput. However, the aspect ratio is correct.

If you are looking for the aspect ratio for the correct size for AVCaptureVideoPreviewLayer, you don't need to worry. Just set the frame to whatever frame you want to fit it in, and it will center the preview with the correct aspect ratio automatically. On iOS 7 it has a clear background, so it all just works.