0

デバイスの向きがオフのときに横長モードで画像をキャプチャするアプリケーションを開発しています。GPUImageStillCamera画像のキャプチャに使用しています。しかし、画像の回転に問題があります。問題は、デバイスの回転をオフにして横向きモードで画像をキャプチャしてギャラリーに保存すると、デバイスの回転をオンにして画像をデバイスの向きで回転させる必要があることです。ただし、デバイスを縦向きモードで保持している場合、画像は横向きであり、デバイスを横向きに保持している場合、画像の回転は UpsideDown です。

ノート

デバイスの回転をオンにしてキャプチャすると、画像の回転が完璧に機能します。問題は、デバイスの回転がオフの場合の横向きモードの画像のみです。このような多くのソリューションを試しました。しかし、私にはうまくいきませんでした。

どんな助けでも大歓迎です。ありがとう

4

1 に答える 1

0

この問題を解決しました。accelerometer'sデバイスの向きが の場合でも回転を取得するために、回転を検出してみましたOFF。プロジェクトに追加CoreMotion.framerworkします。次に、にインポートCMMotionManager.hしますviewController。にviewDidLoad、次のコードを追加します。

self.motionManager = [[CMMotionManager alloc] init];
    self.motionManager.accelerometerUpdateInterval = 1;

    if ([self.motionManager isAccelerometerAvailable])
    {
        NSOperationQueue *queue = [[NSOperationQueue alloc] init];
        [self.motionManager startAccelerometerUpdatesToQueue:queue withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {
            dispatch_async(dispatch_get_main_queue(), ^{

                float xx = -accelerometerData.acceleration.x;
                float yy = accelerometerData.acceleration.y;
                float angle = atan2(yy, xx);

                // could fire a custom shouldAutorotateToInterfaceOrientation-event here.
                if(angle >= -2.25 && angle <= -0.75)
                {
                    if(_deviceOrientation != UIInterfaceOrientationPortrait)
                    {
                        _deviceOrientation = UIInterfaceOrientationPortrait;
                    }
                }
                else if(angle >= -0.75 && angle <= 0.75)
                {
                    if(_deviceOrientation != UIInterfaceOrientationLandscapeRight)
                    {
                        _deviceOrientation = UIInterfaceOrientationLandscapeRight;
                    }
                }
                else if(angle >= 0.75 && angle <= 2.25)
                {
                    if(_deviceOrientation != UIInterfaceOrientationPortraitUpsideDown)
                    {
                        _deviceOrientation = UIInterfaceOrientationPortraitUpsideDown;
                    }
                }
                else if(angle <= -2.25 || angle >= 2.25)
                {
                    if(_deviceOrientation != UIInterfaceOrientationLandscapeLeft)
                    {
                        _deviceOrientation = UIInterfaceOrientationLandscapeLeft;
                    }
                }
            });
        }];
    } else
        NSLog(@"not active");
于 2015-03-05T11:09:24.600 に答える