determining ios camera aspect ratio - ios

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.

for swift
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

Related

How can I have a camera on a defined part of the screen on iPhone 4/4S?

I am using the AVFoundation framework to have a camera view on my iPhone app.
On iPhone 5 and further, the camera fills the entire view where it's in. On iPhone 4/4S, the view isn't filled entirely and I get blank spaces on both sides of the view. I believe it's not because of the constraints, but because of the proportion of the iPhone's screen :
With the preset AVCaptureSessionPresetPhoto, on iPhone 5/6, the ratio of the image is 3/4. On iPhone 4/4S with the same preset, the ratio of the image is 9/16. It looks like the shape of my camera's view can be filled with a 3/4 image, not a 9/16 image.
So I looked for all the preset available, and I tried the preset AVCaptureSessionPreset640x480 thinking that the problem would be solved since 640*480 delivers a 3/4 image... But it didn't fixed anything, I still have blank spaces on both sides of the view.
Is there a way to adapt the resolution with the AVFoundation framework ?
(I think my problem would be easier to understand with images, but I'm not authorized to post some yet)
I didn't found a way to use the camera on the exact ratio i wanted, so I just created a new ViewController that I only use on the iPhone 4/4S, with a different interface for this device

How to set zoom level of camera using AVFoundation framework in IOS?

I am developing a custom camera in which the camera is set to the Image Capture mode. I need to increase the zoom level of camera preview according to the app requirements. The preview currently being displayed is perfect I just need to increase the zoom-out in current preview. I searched over internet but didn't find any solution. Please tell me how can I do this. I am attaching the example image for better understanding. first image is of my camera app and second image is of Scanner Pro app which shows view with more covered area while I focus both the apps for the same object on the same distance. My camera don't have any space but the Scanner camera has spacing all over the image. Both the camera are on the same distance from the paper.
i don't know whether you still need this answer. Probably not, but still for you and everyone else looking out:
When you set the Session Preset, try using SessionPresetPhotofor the device object. This should resolve the weird zoom issue.
Your preview view is probably spilling over the edge of the screen. Make sure it is a 4:3 aspect ratio and that it doesn’t overflow your screen edges. With that you should see more of your image.

iOS wrong orientation when using front camera on UIImagePickerController

I'm using UIImagePickerController to snap an image and uploading it to server.
When taking a photo in the front camera, the height/width get reversed somewhere.
The image is displayed correctly later, but height and width are reversed (and I'm using them for the UIImageView autolayout constraint)
The thing is - that when looking at UIImagePickerControllerMediaMetadata of front and back camera images - the EXIF and the rest of the metadata is the same (resolution is smaller but the height/width ratio is the same)
Any ideas what is the difference?
Apple images are always landscape left with EXIF and the orientation is specified in the EXIF.
OK, so #zaph comment is correct, apparently back camera images are "reversed" as well - the upload code in the server (Codeigniter PHP) ignored the EXIF.
The problem surfaced only due to front camera low resolution...

Getting the full camera view

When your taking a photo with a camera, your not getting all the camera view right?
I mean in a portrait photo take
I will have much more hight then a landscape photo:
Where ill have much more width, right?
But the camera is a circle so that means the the image can be actuality taken with a larger area, I mean the hight and the width together!
The camera is probably getting the hole image, but cropping it according to the screen, landscape or portrait.
If i would like to get the full image that the camera is getting, how can i achieve that?
Any suggestions would be much appreciated, thanks!
Edit
After a long search that came out with nothing so far, even if someone knows about a way to display a landscape camera, in a portrait mode, that would help to.
What i mean is display a view were there is more to see on the left and right sids, hope i'm clear enough with my question..
Actually, the sensor has roughly the same proportions as the screen. Its aspect ration is around 1.33 (4/3) or maybe 1.5 (3/2), depends on the phone model. the only round thing in the camera is the lens that projects a circle of light around the sensor. When you rotate your phone the sensor is naturally rotated as well so you always get the full output in every shot.

iPhone gallery app crops photo to 3:2 from 4:3 aspect ratio, how?

The photo taken using the UIImagePickerController is of 4:3 aspect ratio. However, the full screen aspect ratio is 3:2. So the gallery app is doing some magic to show the photo as 3:2 aspect ratio. When you zoom out in the full screen view, the photo appears in 4:3 aspect ratio. Can anyone shed light on how it could be done? I've been breaking my head for the past two weeks on this.
Really appreciate the help!!
To fit a 4:3 image into a 3:2 space you can either match the height or match the width.
If you were to match the height then you'd turn the 3 in 4:3 into the 2 in 3:2. So you'd scale the entire image by 2/3. Since you'd be scaling width and height by the same amount, the effective height after scaling would be the 4 from 4:3 scaled by 2/3, to give 8/3 — a bit less than three. You'd therefore not quite fill the screen.
Conversely, if you were to match the width then you'd turn the 4 in 4:3 into the 3 in 3:2. So you'd scale the entire image by 3/4. Since you'd be scaling width and height by the same amount, the effective height at the end would be the 3 from 4:3 scaled by 3/4, to give 9/4 — a bit more than two. You'll therefore slightly more than fill the screen.
So that the photos app does is display pictures with an initial zoom so as to fit the width of the stored image to the width of the display. If the stored image is 3264x2448 (which I think it is on the iPhone 4S and the 5) then on an iPhone 4s — using points rather than pixels — it's scaled by a ratio of 480/3264. If you work that out, it gives the image a final height of very close to 360pt, 40pt wider than the screen.
In terms of UIKit, that probably means putting a UIImage inside a UIScrollView and setting the initial value of zoomScale to 480/3264 (ie, approximately 0.15). The scroll view can help you with zooming in and out though there's still some manual work to be done — see e.g. this tutorial. By setting a minimumZoomScale of 320/2448 (ie, approximately 0.13) you'll automatically get the behaviour where zooming out as far as you can go ends up showing the entire 4:3 image on screen.
not sure how you obtain your image, but you might have gotten one of the representations of the image. One of those representations is specifically for getting a quick fullScreen CGImage, an other will return the FullResolution. FullScreen will be whatever is needed for the device (640x960 on iPhone4), Full resolution would be the 8MP picture.

Resources