2012-01-22 64 views
0

我正在嘗試使用CISourceOverCompositing過濾器,但我正在碰壁。CISourceOverCompositing在設備和模擬器上產生不同的結果

這是相關代碼。掩模是UIImage和圖像是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通道來混合圖像。

幾乎相同的代碼使用CoreGraphics的API工作正常(但我不能申請其他CIFilters)

我可能會嘗試使用CIBlendWithMask但後來我不得不提取面罩和增加複雜性。 ..

回答

1

在您的文件名和指定的文件中尋找不同的大小寫。他們不一定要在模擬器中工作,但在設備上區分大小寫。這已經讓我失望了很多次,如果你不尋找它,追查很難。

1

好的我發現這個問題,這有點棘手。首先,爲了回答傑西亞,掩碼和基地都生成了,所以這裏的路徑是不相關的(但我會記住這一點,明確知道)。

現在爲「解決方案」。在生成掩碼時,我在後臺上下文中使用CG *調用的組合(CGImageCreateWithMask,...)。現在看起來,這些調用的結果似乎給了我一個似乎沒有alpha通道的CGImageCGImageGetAlphaInfo返回0),但是... CoreGraphics APIs在設備和模擬器中以及CoreImage API中,但只在模擬器中應用仍然存在的alpha通道。

kCGImageAlphaPremultipliedLast創建一個CGContext上,並使用CGContextDrawImagekCGBlendModeSourceOut(或任何你需要「挖空」你的形象)保持alpha通道完好,這部作品在模擬器和設備兩者。

我將提交一個雷達作爲模擬器或設備是錯誤的。

相關問題