【问题标题】:Rotating an image prior to saving in iOS在 iOS 中保存之前旋转图像
【发布时间】:2011-09-03 20:56:45
【问题描述】:

在我的应用中,我需要保存一张图片。即使设备处于横向模式,我也需要始终将图像保存为纵向。我正在检查设备是否处于横向模式,如果是,我想在保存为 PNG 之前旋转我的图像。谁能帮我解决这个问题?

-(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];

}

【问题讨论】:

标签: iphone ios uiimage rotation cgimageref


【解决方案1】:

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

【讨论】:

  • 好主意,但没有快乐。图像本身必须旋转。当视图首次加载时,它会查看图像并根据设备方向旋转它,我需要将其始终保存为纵向以使其正常工作。我已经尝试在保存之前旋转 imageView,但这也不起作用
猜你喜欢
  • 2014-12-09
  • 1970-01-01
  • 2011-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多