1

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.

1
  • 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. Commented Dec 4, 2013 at 19:36

3 Answers 3

6

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.

1
  • Am I missing something? This is not the correct aspect ratio of the iPhone 4S camera.
    – lm2s
    Commented Apr 11, 2015 at 10:23
0

for swift

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

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

1
  • 2
    This is obviously not at all reliable and is basically a guaranteed bug. Additionally to your comment, the picture could be a screenshot (not necessarily the same resolution as the camera), or could be a photo that was edited (iOS 7).
    – prewett
    Commented Feb 19, 2014 at 13:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.