I working on ios app. My application can take photo, I need change camera's aspect ratio to 1:1.
How to change the aspect ratio on iOS ?
Related
How can I change the resolution ratio in RTCCameraVideoCapturer?
I choose a AVCaptureDevice.Format, and the resolution ratio is 1280*720. I want to preview it on a fullfill screen view. How can I change the resolution ratio 1280*720 into 1334*750. Should I zoom or something else?
If I create an image view that has constraints that are proportional to the size of the screen. I can't decide the exact dimensions of image I need to supply for any of x1, x2 or x3. I understand how image sets work. But it's figuring out the dimensions I need because when I the following code I get slightly different dimensions for every device I test on:
print(imageView.bounds.size.width)
print(imageView.bounds.size.height)
Different x2 devices like the iPhone 5 and iPhone 6 will give me slight differences. But because they receive the same image, will it not look different?
Add an Aspect Ratio constraint on your UIImageView to make sure you don't stretch the image.
Use Aspect Fill or Aspect Fit content mode for UIImageView.
Keep the biggest image for each scale factor (2x, 3x). Basically, there are multiple device resolutions for 2x scale factor, so #2x image should have resolution designed for iPhone 6 and it will be automatically downscaled on smaller devices (iPhone 5/4s). 3x image should have resolution for
So I'm trying to create a user profile that has a user picture that changes sizes with the screen size so it doesn't take up too much space on the smaller iPhone screens.
Everything else in my simulator is sizing correctly during simulation, but the user picture changing size correctly without breaking the ability to stay circular. I tried using aspect ratio, but the picture stays the same size when I simulate on smaller screens. I tried using aspect ratio in relation to the whole view (so that it changes sizes depending on the view), but since the view is rectangular, the picture cannot hold it's ability to stay circular (since it needs to be a square to correctly make the picture circular).
How would I achieve this without creating different views for each phone screen size?
If you set the contentMode of your UIImageView to UIViewContentModeScaleAspectFit, it doesn't matter if the view itself is not square - the image will always show in the right 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.
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
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.