2016-09-26 80 views
1

下面的代码不再适用于iOS10。图像数据保持不旋转。在iOS10上是否有[UIImage imageWithCIImage:scale:orientation]损坏?

我已确认,此代码适用于iOS 8和9

CIImage *i = [[CIImage alloc] initWithImage:image]; 
imageView.image = [UIImage imageWithCIImage:i scale:image.scale orientation:UIImageOrientationRight]; 

有没有人遇到同样的问题?这是一个错误还是预期的改变?

回答

2

我的猜测是,UIImageView处理图像旋转标志的方式有所改变。我找不到任何地方提到的变化,但至少下面的代码是可行的。 Taken from here

- (UIImage*)rotateImage:(UIImage*)sourceImage clockwise:(BOOL)clockwise 
{ 
    CGSize size = sourceImage.size; 
    UIGraphicsBeginImageContext(CGSizeMake(size.height, size.width)); 
    [[UIImage imageWithCGImage:[sourceImage CGImage] 
         scale:1.0 
        orientation:clockwise ? UIImageOrientationRight : UIImageOrientationLeft] 
    drawInRect:CGRectMake(0,0,size.height ,size.width)]; 

    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    return newImage; 
} 
0

如果您需要更改CIImage的方向,请尝试此操作。

let newCIImage: CIImage 
if #available(iOS 11.0, *) { 
    newCIImage = myCIImage.oriented(.right) 
} else { 
    newCIImage = myCIImage.oriented(forExifOrientation: Int32(CGImagePropertyOrientation.right.rawValue)) 
}