1

UIImageからを受け取り、AVCaptureSessionに設定していますUIImageView。ポートレート モードでは画像が正しい向きに設定されますが、ランドスケープ モードを使用すると、画像が時計回りに 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 に答える