2016-09-26 75 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)) 
}