使用 GPUImageStillCamera 在横向模式下捕获的图像的方向问题

Issue with orientation of Image captured in landscape mode with GPUImageStillCamera

我正在开发一个应用程序,当设备方向关闭时,我可以在横向模式下捕获图像。我正在使用 GPUImageStillCamera 来捕捉图像。但是我在图像旋转方面遇到了问题。问题是,当我在关闭设备旋转的情况下以横向模式捕获图像并保存在图库中时,然后打开设备旋转并且图像必须随着设备方向旋转。但是当设备处于纵向模式时图像是横向的,如果设备处于横向模式,图像旋转是颠倒的 .

备注

Image rotation works perfect when captured with device rotation ON. Issue is only with image in landscape mode when device rotation OFF. I have tried many solutions like this one. But didn't work for me.

如有任何帮助,我们将不胜感激。谢谢

我找到了这个问题的解决方案。我试图检测 accelerometer's 旋转以获取旋转,即使设备方向为 OFF。将 CoreMotion.framerwork 添加到您的项目。然后在你的 viewController 中导入 CMMotionManager.h。在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");