1

我正在接收我UIImage的 'sAVCaptureSession并将它们设置为UIImageView's。纵向模式将图像设置为正确的方向,但是一旦我使用横向模式,图像就会顺时针旋转 90 度。

我做了一些研究,发现我可以使用UIImageOrientation这种方法来解决我的问题:

[UIImage imageWithCGImage:cgimageref scale:1 orientation:orientation]

但我不明白怎么做。如果我查看UIImageOrientation所有图像,纵向和横向模式下的值始终为 3 ( NSLog(@"%d",UIImageOrientation))。我很困惑这对我有什么帮助。我错过了什么吗?

这是方向代码:

-(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
  self.prevLayer.frame = self.view.bounds;
  self.prevLayer.orientation = [[UIDevice currentDevice] orientation];
}

shouldAutorotateToInterfaceOrientation 返回 YES。

4

1 回答 1

4

解决方案花了一些时间才找到。我必须向 AVCaptureConnection 添加方向

AVCaptureConnection *videoConnection = nil;
for (AVCaptureConnection *connection in stillImageOutput.connections){
    for (AVCaptureInputPort *port in [connection inputPorts]){
        if ([[port mediaType] isEqual:AVMediaTypeVideo] ){
            videoConnection = connection;
            break;
        }
    }
    if (videoConnection) { break; }
}

下面的这一行是修复:

if([videoConnection isVideoOrientationSupported]) {
    [videoConnection setVideoOrientation:[[UIDevice currentDevice] orientation]];
}

所有图像都可以在任何方向上正常工作。

于 2012-03-30T03:29:35.447 回答