Reputation: 2426
The following code does no longer work on iOS10. The image data remains unrotated.
I have confirmed that this code works on iOS 8 and 9.
CIImage *i = [[CIImage alloc] initWithImage:image];
imageView.image = [UIImage imageWithCIImage:i scale:image.scale orientation:UIImageOrientationRight];
Has anyone run into this same problem? Is this a bug, or an intended change?
Upvotes: 3
Views: 527
Reputation: 2172
If you need to change the CIImage's orientation, please try this.
let newCIImage: CIImage
if #available(iOS 11.0, *) {
newCIImage = myCIImage.oriented(.right)
} else {
newCIImage = myCIImage.oriented(forExifOrientation: Int32(CGImagePropertyOrientation.right.rawValue))
}
Upvotes: 0
Reputation: 2426
My guess is that something has changed in terms of how UIImageView handles image rotation flags. I can't find the changes mentioned anywhere, but at least the code below works. 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;
}
Upvotes: 2