在我的 iPhone 应用程序中,我一直使用以下函数来水平镜像
图像。
-(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;
}
虽然在 iOS 10.0.1 中,这个函数仍然可以正常运行,但是当我尝试使用这个函数中的 UIImage
时,会出现以下警告,并且图像似乎不存在在那里。
Failed to render 921600 pixels because a CIKernel's ROI function did not allow tiling.
当我尝试使用UIImage
(在此代码的第二行)时,此错误实际上出现在“输出”窗口中:
UIImage* flippedImage = [self mirrorImage:originalImage];
UIImageView* photo = [[UIImageView alloc] initWithImage:flippedImage];
调用mirrorImage
后,flippedImage
变量确实包含一个值,它不是nil
,但是当我尝试使用图像,我收到错误消息。
如果我不调用 mirrorImage
函数,那么代码可以正常工作:
UIImageView* photo = [[UIImageView alloc] initWithImage:originalImage];
iOS 10
是否有一些新的怪癖会阻止我的 mirrorImage
功能工作?
只是补充一下,在 mirrorImage
函数中,我尝试测试转换前后图像的大小(因为错误是提示必须 tile
图像),并且大小相同。
最佳答案
我通过转换 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)
关于iOS 10 : CIKernel's ROI function did not allow tiling,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40739037/