我正在使用相机拍摄图像 captureStillImageAsynchronouslyFromConnection
这些图像被颠倒了.我尝试使用保存图像
UIImage *flippedImage = [UIImage imageWithCGImage:image.CGImage scale:image.scale orientation:UIImageOrientationUp]
Run Code Online (Sandbox Code Playgroud)
但是此方向仅在元数据中,当我从文件中复制数据以处理它时,处理后的图像是颠倒的.(快速查看原件直立,但处理/过滤的图像是颠倒的).
设置视频捕获方向的正确方法是什么?
我在视频预览图层上设置了方向,但这不会影响AVCaptureStillImageOutput对象缓冲区中捕获的数据.
我读了AVCaptureStillImageOutput标题,但似乎没有解释如何强制相机预览图像缓冲区的方向.
例如 - (AVMetadataObject *)transformedMetadataObjectForMetadataObject:(AVMetadataObject *)metadataObject connection:(AVCaptureConnection *)connection NS_AVAILABLE_IOS(6_0);
谢谢
“问题”是图像方向,iOS 相机仅以一个方向返回图像,除非您设置了-videoOrientation转换已拍摄图像的属性。所以可能会出现不同的问题:
videoOrientation设置不正确videoOrientation根本没有设置videoOrientation 属性仅适用于静态图像和视频捕获,不适用于单个缓冲区。
此片段取自 Apple AVCam示例代码。
[[[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>
Run Code Online (Sandbox Code Playgroud)
首先它根据预览视图设置方向,然后进行拍摄,然后以正确的方向将其保存在资源库中
| 归档时间: |
|
| 查看次数: |
3708 次 |
| 最近记录: |