AVCaptureStillImageOutput图像倒置返回 [英] AVCaptureStillImageOutput Image returning upside down

查看:80
本文介绍了AVCaptureStillImageOutput图像倒置返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用captureStillImageAsynchronouslyFromConnection

图像倒置保存.我尝试使用

The images are being saved upside down. I tried saving the image using

UIImage *flippedImage = [UIImage imageWithCGImage:image.CGImage scale:image.scale orientation:UIImageOrientationUp]

但是此方向仅在元数据中,当我从文件中复制数据以对其进行处理时,处理后的图像会颠倒过来. (快速浏览显示的原件是直立的,但是经过处理/过滤的图像是上下颠倒的.)

but this orientation is only in the metadata and when I copy the data from the file to process it the processed images are upside down. (Quick look shows the originals upright, but the processed/filtered images are upside down).

设置视频拍摄方向的正确方法是什么?

What is the correct way to set the orientation for the video capturing?

我在视频预览层上设置了方向,但这不会影响AVCaptureStillImageOutput对象缓冲区中捕获的数据.

I set the orientation on the video preview layer but that doesn't effect the captured data in the AVCaptureStillImageOutput object's buffer.

我阅读了AVCaptureStillImageOutput标头,但似乎没有解释如何将相机预览方向强制到图像缓冲区.

I read the AVCaptureStillImageOutput header but there doesn't seem to be an explanation of how to force the camera previews orientation to the image buffer.

例如- (AVMetadataObject *)transformedMetadataObjectForMetadataObject:(AVMetadataObject *)metadataObject connection:(AVCaptureConnection *)connection NS_AVAILABLE_IOS(6_0);

谢谢

推荐答案

问题"是图像方向,iOS相机仅以一种方向返回图像,除非您设置了-videoOrientation属性以转换已经拍摄的图像.因此可能会有不同的问题:

The "problem" is the image orientation, iOS camera returns images only in one orientation, except if you set the -videoOrientation property that transform already the image taken. So there can be different problems:

  1. videoOrientation未正确设置
  2. videoOrientation未设置为全部
  1. videoOrientation non set correctly
  2. videoOrientation not set at ALL

videoOrientation属性仅适用于静态图像和视频捕获,不适用于单个缓冲区.
此代码段摘自Apple AVCam 示例代码.

The videoOrientation property works only for still images and video capturing, not for single buffers.
This snippet is tanken from Apple AVCam sample code.

    [[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] setVideoOrientation:[[(AVCaptureVideoPreviewLayer *)[[self previewView] layer] connection] videoOrientation]];

    [AVCamViewController setFlashMode:AVCaptureFlashModeAuto forDevice:[[self videoDeviceInput] device]];

    [[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {

        if (imageDataSampleBuffer)
        {
            NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
            UIImage *image = [[UIImage alloc] initWithData:imageData];
            [[[ALAssetsLibrary alloc] init] writeImageToSavedPhotosAlbum:[image CGImage] orientation:(ALAssetOrientation)[image imageOrientation] completionBlock:nil];
        }
    }]; <br>

首先,它根据预览视图设置方向,然后进行拍摄,然后将其以正确的方向保存在资产库中

First it sets the orientation according to the preview view, later it takes the shot, and later it saves it on the asset library with correct orientation

这篇关于AVCaptureStillImageOutput图像倒置返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆