如何在风景模式下拍照 [iOS8]?

How to take a photo in landscape mode [iOS8]?

我有一个应用程序需要拍照,然后通过在其上绘图来制作 png 图层。我的 png 层是绝对正确的,并且具有横向维度。

但是当我上传我拍的照片时,它有纵向尺寸。

 - (void)takePhoto {
    AVCaptureConnection *videoConnection = nil;
    for (AVCaptureConnection *connection in StillImageOutput.connections) {
        for (AVCaptureInputPort *port in [connection inputPorts]) {
            if ([[port mediaType] isEqual:AVMediaTypeVideo]) {
                videoConnection = connection;
                break;
            }
        }
    }
    [StillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
        if (imageDataSampleBuffer != NULL) {
            NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
            UIImage *image = [UIImage imageWithData:imageData];

            UIImage *ipadImage = [self imageRotatedByDegrees:image deg:0];

            NSLog(@"image orientation: %ld", (long)image.imageOrientation);
            NSLog(@"image width: %f , height: %f", image.size.width, image.size.height);

            captured.image = ipadImage;

感谢您的帮助!

Apple 使用 EXIF 标签指定方向,并且始终使用相同的尺寸方向(横向),无论拍摄照片时 phone 的姿势如何。大多数平台不考虑 EXIF 方向,这会带来互操作性问题。

为了互操作性,可能需要在上传之前旋转图片并更改 EXIF 标签以匹配。

有关详细信息,请参阅 EXIF Orientation Handling Is a Ghetto