2011-09-03 143 views
2

在我的应用程序中,我需要保存图像。即使设备处于横向模式,我也需要将图像始终保存为肖像。我正在检查设备是否处于横向模式,如果是,我想在将图像保存为PNG之前旋转图像。任何人都可以帮我解决这个问题吗?在保存iOS之前旋转图像

-(void) saveImage { 

     UIGraphicsBeginImageContext(self.view.bounds.size); 
     [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
     UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 

     if (UIInterfaceOrientationIsLandscape([[UIDevice currentDevice] orientation])) { 
      //// need to rotate it here 
     } 

     NSData *data = UIImagePNGRepresentation (viewImage);  

     [data writeToFile:savePath atomically:YES]; 

} 
+0

你有没有想过这个?我在这里问基本相同的问题:http://stackoverflow.com/questions/20764623/rotate-newly-created-ios-image-90-degrees-prior-to-saving-as-png ...我' d爱任何你可以提供的帮助。 :) –

回答

0

This thread可能会帮助你。它显示了如何使用UIImageimageOrientation方法来切换方向。希望有助于!

+0

好想法,但没有喜悦。图像本身必须旋转。当视图第一次加载时,它会查看图像并根据设备方向旋转它,我需要它始终保存为肖像以便正确工作。我试图在保存之前旋转imageView,但这也不会工作 – Brodie