【问题标题】:CISourceOverCompositing produce different results on device and in simulatorCISourceOverCompositing 在设备和模拟器上产生不同的结果
【发布时间】:2012-01-23 20:05:22
【问题描述】:

我正在尝试使用 CISourceOverCompositing 过滤器,但我遇到了一些问题。

这是相关代码。 mask 是 UIImage,images 是 UIImage 的数组

ci_mask = [[CIImage alloc] initWithCGImage: mask.CGImage];
ctx = [CIContext contextWithOptions: nil];
compo = [CIFilter filterWithName: @"CISourceOverCompositing"];
for(int i = 0; i < images.count; i++) {
  UIImage *image = [images objectAtIndex: i];
  ci_base = [[CIImage alloc] initWithCGImage: image.CGImage];
  [compo setDefaults];
  [compo setValue: ci_mask forKey: @"inputImage"];
  [compo setValue: ci_base forKey: @"inputBackgroundImage"];
  result = compo.outputImage;

  CGImageDestinationAddImage(
    dst_ref,
    [ctx createCGImage: result fromRect:result.extent],
    frame_props
  );
}

mask 包含一个 alpha 通道,它在模拟器中正确应用但在设备上没有。输出仅按原样显示蒙版,而不使用 Alpha 通道来混合图像。

使用 CoreGraphics API 的几乎相同的代码工作正常(但我不能应用其他 CIFilters)

我可能会尝试使用CIBlendWithMask,但随后我将不得不提取掩码并增加复杂性...

【问题讨论】:

    标签: iphone ios ios5 core-image


    【解决方案1】:

    在您的文件名和指定的文件中寻找不同的大小写。它们不必在模拟器中使用相同的大小写,但它们在设备上区分大小写。这让我多次失望,如果你不寻找,很难追查到。

    【讨论】:

      【解决方案2】:

      好的,我发现了这个问题,这有点棘手。首先,回答 Jeshua,掩码和基础都是生成的,因此路径在这里不相关(但我会记住这一点,绝对很高兴知道)。

      现在是“解决方案”。在生成掩码时,我在背景上下文(CGImageCreateWithMask,...)上使用了 CG* 调用的组合。现在,这些调用的结果似乎给了我一个 CGImage 似乎没有 alpha 通道(CGImageGetAlphaInfo 返回 0)但是......设备和模拟器上的 CoreGraphics API 和 CoreImage API 但仅在模拟器中应用仍然存在 Alpha 通道。

      使用 kCGImageAlphaPremultipliedLast 创建一个 CGContext 并使用 CGContextDrawImagekCGBlendModeSourceOut(或任何你需要“挖空”你的图像)保持 alpha 通道完好无损,这在模拟器和设备上都有效。

      如果模拟器或设备有问题,我将提交雷达。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-04-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-03-26
        • 2014-05-27
        相关资源
        最近更新 更多