简体   繁体   中英

determining ios camera aspect ratio

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.

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.

为了迅速

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM