对于那些需要使用CIImage和缓冲区方向的人是错误的,我使用了这种修正。
就这么简单。顺便说一句,号码3,1,6,8是从这里https://developer.apple.com/reference/imageio/kcgimagepropertyorientation
不要问我为什么3,1,6,8是正确的组合。我用蛮力法找到它。如果你知道为什么让解释的意见,请...
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
{
// common way to get CIImage
CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CFDictionaryRef attachments = CMCopyDictionaryOfAttachments(kCFAllocatorDefault, sampleBuffer, kCMAttachmentMode_ShouldPropagate);
CIImage *ciImage = [[CIImage alloc] initWithCVPixelBuffer:pixelBuffer
options:(__bridge NSDictionary *)attachments];
if (attachments) {
CFRelease(attachments);
}
// fixing the orientation of the CIImage
UIInterfaceOrientation curOrientation = [[UIApplication sharedApplication] statusBarOrientation];
if (curOrientation == UIInterfaceOrientationLandscapeLeft){
ciImage = [ciImage imageByApplyingOrientation:3];
} else if (curOrientation == UIInterfaceOrientationLandscapeRight){
ciImage = [ciImage imageByApplyingOrientation:1];
} else if (curOrientation == UIInterfaceOrientationPortrait){
ciImage = [ciImage imageByApplyingOrientation:6];
} else if (curOrientation == UIInterfaceOrientationPortraitUpsideDown){
ciImage = [ciImage imageByApplyingOrientation:8];
}
// ....
}
'住宅“videoOrientation”在类型的对象AVCaptureSession *'' – cheeesus 2012-10-03 16:35:27
右未找到回答,应该被接受。 – Rivera 2013-03-11 00:23:08
@cheesus videoOrientation在AVCaptureConnection,而不是AVCaptureSession – GabCas 2013-08-28 15:34:45