【问题标题】:iOS 10: CIKernel's ROI function did not allow tilingiOS 10:CIKernel 的 ROI 功能不允许平铺
【发布时间】:2017-04-05 23:04:57
【问题描述】:

在我的 iPhone 应用中,我一直使用以下函数来horizontally mirror 一张图片。

-(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图像),并且大小是相同的。

【问题讨论】:

    标签: ios objective-c iphone uiimage


    【解决方案1】:

    我通过转换 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)
    

    【讨论】:

      【解决方案2】:

      没关系。

      我不知道iOS 10 出了什么问题,但我设法通过用这个替换我的函数来解决问题:

      -(UIImage*)mirrorImage:(UIImage*)img
      {
          UIImage* flippedImage = [UIImage imageWithCGImage:img.CGImage
                                                      scale:img.scale
                                                orientation:UIImageOrientationUpMirrored];
          return flippedImage;
      }
      

      【讨论】:

        猜你喜欢
        • 2018-07-24
        • 1970-01-01
        • 1970-01-01
        • 2018-11-13
        • 2021-08-02
        • 1970-01-01
        • 2023-03-09
        • 2010-10-17
        • 1970-01-01
        相关资源
        最近更新 更多