【问题标题】:Issue with orientation of Image captured in landscape mode with GPUImageStillCamera使用 GPUImageStillCamera 在横向模式下捕获的图像的方向问题
【发布时间】:2015-05-01 02:15:18
【问题描述】:
我正在开发一个应用程序,我在设备方向关闭时以横向模式捕获图像。我正在使用GPUImageStillCamera 捕获图像。但是我在图像旋转方面遇到了问题。问题是,当我在设备旋转关闭的情况下以横向模式捕获图像并保存在图库中时,打开设备旋转并且图像必须随设备方向旋转。但是在纵向模式下手持设备时图像是横向的,如果在横向模式下手持设备,图像旋转是颠倒的
.
注意
在设备旋转开启的情况下拍摄时,图像旋转效果很好。
问题仅出现在设备旋转关闭时横向模式下的图像。
我尝试了许多解决方案,例如this one。但没有为
我。
任何帮助将不胜感激。谢谢
【问题讨论】:
标签:
landscape
image-rotation
ios8.1
device-orientation
gpuimagestillcamera
【解决方案1】:
我已经解决了这个问题。即使设备方向为OFF,我也尝试检测accelerometer's 旋转以获得旋转。将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");