photo output orientation

I am using ios 11, swift 4 and capturing a picture with av foundation library. I have a custom preview as shown and mysettings are as suggested. The problem is when I capture and save the CMSample buffer, it is leftLandscape oriented. I tried to change CapturePhotoOutput orientation but it resist to change?(changing photoOutputConnection.videoOrientation changes nothing?)

Replies

Erall

I have a similar question, posted not long after yours, with an example of the code I think is in issue.

Apple have a sample app, AvCam, which saves images to the Photos app and works as expected, but I've had no luck at all pinpointing exactly what is wrong with my own code. You might want to take a look as well...

AVCapturePhotoOutput does pay attention to its connection.videoOrientation, but it doesn't physically rotate buffers like VideoDataOutput does. Instead it makes note of the Exif orientation you desire. When you write the buffer to any of the standard still image containers (JPEG, HEIC, DNG, TIFF, etc), the image is rotated and/or flipped appropriately at display time.

Cool, so whats the fix?

Hi Erral

did you figure this out?

My two cents, when you set photoOutputConnection.videoOrientation, it basically just tags an metadata into to the photo you took, so that later on You can do some further image processing like flipping, rotating, whatever...


My guessing, you will need to rotate the photo by yourself after taking it.

you might want to check this out https://forums.developer.apple.com/thread/102884


i had the same problem, I was converting the camera data to a uiimage (for preview) and then saving that. Orientation data was then lost. Problem was solved, thanks to bford, by simply saving the image first and then showing it in a preview. No need to rotate or do anything funky, other than perhaps delete it if the user chose not to save. In my case I dropped the preview functionality as it was a pain in real use. Apples camera app doesn’t preview before saving so, given the fact they’ve no doubt put a lot of errort into creating a smooth user experience, I chose to follow their lead.