Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ios

ios10

uiimage

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?

like image 244
Nailer Avatar asked Dec 05 '25 03:12

Nailer


1 Answers

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;
}
like image 180
Nailer Avatar answered Dec 07 '25 18:12

Nailer