對於那些需要使用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