如何在横向模式下拍摄照片[iOS8]?

时间:2015-09-02 15:00:40

标签: objective-c xcode 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;

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

Apple使用EXIF标签指定方向,并始终使用相同的尺寸方向(横向),无论拍摄照片时手机的握持方式如何。大多数平台都不会将EXIF方向考虑在内,这会带来互操作性问题。

对于互操作性,可能需要在上传之前旋转图像并更改EXIF标记以匹配。

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