Note that there are some explanatory texts on larger screens.

plurals
  1. POWeird behavior when rotating AVFoundation stills on iOS
    primarykey
    data
    text
    <p>OK, so the following code works, but I don't get why. I am capturing still images from the Front camera using AVFoundation. I have this code before initiating capture:</p> <pre><code>if ([connection isVideoOrientationSupported]) { AVCaptureVideoOrientation orientation; switch ([UIDevice currentDevice].orientation) { case UIDeviceOrientationPortraitUpsideDown: orientation = AVCaptureVideoOrientationPortraitUpsideDown; break; case UIDeviceOrientationLandscapeLeft: orientation = AVCaptureVideoOrientationLandscapeRight; break; case UIDeviceOrientationLandscapeRight: orientation = AVCaptureVideoOrientationLandscapeLeft; break; default: orientation = AVCaptureVideoOrientationPortrait; break; } [connection setVideoOrientation:orientation]; } </code></pre> <p>and then this in the <code>captureStillImageAsynchronouslyFromConnection:completionHandler:</code> to store the image:</p> <pre><code>NSData *imageData = [AVCaptureStillImageOutputjpegStillImageNSDataRepresentation:imageSampleBuffer]; UIImage *i = [UIImage imageWithData:imageData]; orientation:i.imageOrientation]; UIGraphicsBeginImageContext(i.size); [i drawAtPoint:CGPointMake(0.0, 0.0)]; image.image = UIGraphicsGetImageFromCurrentImageContext(); </code></pre> <p>as you can see, I don't rotate the image or anything, just draw it in the context and save. But as soon as I try to use <code>i</code> it is always rotated by 90 degrees. If I try to rotate it using </p> <pre><code>UIImage *rotated = [[UIImage alloc] initWithCGImage:i.CGImage scale:1.0f orientation:i.imageOrientation]; </code></pre> <p>it doesn't work (no change from just using <code>i</code>).</p> <p>I understand that UIImage might just draw the image into the context using the right orientation automatically, but WTF?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload