3

In my iPhone app, I've always used the following function to horizontally mirror an image.

-(UIImage*)mirrorImage:(UIImage*)img
{
    CIImage *coreImage = [CIImage imageWithCGImage:img.CGImage];
    coreImage = [coreImage imageByApplyingTransform:CGAffineTransformMakeScale(-1, 1)];
    img = [UIImage imageWithCIImage:coreImage scale:img.scale orientation:UIImageOrientationUp];
    return img;
}

With iOS 10.0.1 though, this function still runs with no errors, but when I try to use the UIImage from this function, the following warning appears, and the image just doesn't seem to be there.

Failed to render 921600 pixels because a CIKernel's ROI function did not allow tiling.

This error actually appears in the Output window when I attempt to use the UIImage (in the second line in this code) :

UIImage* flippedImage = [self mirrorImage:originalImage];    
UIImageView* photo = [[UIImageView alloc] initWithImage:flippedImage];

After calling mirrorImage, the flippedImage variable does contain a value, it's not nil, but when I try to use the image, I get that error message.

If I were to not call the mirrorImage function, then the code works fine:

UIImageView* photo = [[UIImageView alloc] initWithImage:originalImage];

Is there some new quirk with iOS 10 which would prevent my mirrorImage function from working ?

Just to add, in the mirrorImage function, I tried testing the size of the image before and after the transformation (as the error is complaining about having to tile the image), and the size is identical.

Ketan Parmar
  • 27,092
  • 9
  • 50
  • 75
Mike Gledhill
  • 27,846
  • 7
  • 149
  • 159

2 Answers2

3

I fixed it by converting CIImage -> CGImage -> UIImage

let ciImage: CIImage = "myCIImageFile"

let cgImage: CGImage = {
    let context = CIContext(options: nil)
    return context.createCGImage(ciImage, from: ciImage.extent)!
}()

let uiImage = UIImage(cgImage: cgImage)
Petro
  • 84
  • 3
1

Never mind.

I don't know what iOS 10 has broken, but I managed to fix the problem by replacing my function with this:

-(UIImage*)mirrorImage:(UIImage*)img
{
    UIImage* flippedImage = [UIImage imageWithCGImage:img.CGImage
                                                scale:img.scale
                                          orientation:UIImageOrientationUpMirrored];
    return flippedImage;
}
Ketan Parmar
  • 27,092
  • 9
  • 50
  • 75
Mike Gledhill
  • 27,846
  • 7
  • 149
  • 159