1
votes

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
No I want to know the aspect ration BEFORE a picture is taken. Aspect ratio is the ratio of the images width to height as taken by the camera.strikerdude10

3 Answers

6
votes

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.

0
votes

for swift

let sizeCamera = CMVideoFormatDescriptionGetPresentationDimensions(backCamera.activeFormat.formatDescription, usePixelAspectRatio: true, useCleanAperture: true);
-4
votes

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