在我的应用中,我需要保存一张图片。我需要将图像始终保存为肖像,即使设备处于横向模式也是如此。我正在检查设备是否处于横向模式,如果是,我想在将图像另存为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];

}

最佳答案

This thread可能会帮助您。它显示了如何使用imageOrientationUIImage方法来切换方向。希望对您有所帮助!

关于iphone - 在保存到iOS中之前旋转图像,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7295836/

10-09 16:34
查看更多