[UIImage imageWithCIImage:scale:orientation] 在 iOS10 上损坏了吗?

Is [UIImage imageWithCIImage:scale:orientation] broken on iOS10?

以下代码不再适用于 iOS10。图像数据保持不变。

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

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

有人 运行 遇到过同样的问题吗?这是错误还是有意更改?

我的猜测是 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;
}

如果你需要改变 CIImage 的方向,请试试这个。

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