首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于GPUImageStillCamera的景观模式下图像的定位问题

基于GPUImageStillCamera的景观模式下图像的定位问题
EN

Stack Overflow用户
提问于 2015-02-28 10:44:14
回答 1查看 215关注 0票数 0

我正在开发一个应用程序,当设备定位关闭时,我将在景观模式下捕获图像。我正在使用GPUImageStillCamera捕捉图像。但我在旋转图像上遇到了问题。问题是,当我捕获图像在景观模式与设备旋转关闭和保存在画廊,然后打开设备旋转和图像必须旋转与设备的方向。但在纵向模式下保持装置时图像处于景观状态,如果保持装置在景观中,则图像旋转为UpsideDown。

Note

当拍摄到与设备旋转有关的图像旋转时,图像旋转非常完美。当设备旋转关闭时,只有在景观模式下才会出现图像问题。我尝试过许多解决方案,比如这一个。但对我不起作用。

任何帮助都将不胜感激。谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-05 11:09:24

我有办法解决这个问题。我尝试检测accelerometer's旋转以获得旋转,即使设备方向是OFF。将CoreMotion.framerwork添加到项目中。然后在您的CMMotionManager.h中导入viewController。在viewDidLoad中,添加以下代码:

代码语言:javascript
复制
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");
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28780806

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档