2012-05-02 52 views
2

爲什麼obj2不與obj1混合,但不使用CGLayer它工作正常,與CGContextDrawLayerAtPoint相同的問題,CGLayer不支持CGContextSetBlendMode?CGLayers爲什麼不混合?

//Layer 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGLayerRef objectLayer = CGLayerCreateWithContext (context, rect.size, NULL); 
    CGContextRef objectContext = CGLayerGetContext (objectLayer); 
    //obj1 
    CGContextDrawImage(objectContext, CGRectMake(0, 0, rect.size.width, rect.size.height), [[UIImage imageNamed:@"background.png"] CGImage]); 
    //obj2 
    CGContextSetBlendMode(objectContext, kCGBlendModeSoftLight); 
    CGContextSetAlpha(objectContext, 0.5f); 
    CGContextDrawImage(objectContext, CGRectMake(0, 0, rect.size.width, rect.size.height), [[UIImage imageNamed:@"overlay1.png"] CGImage]); 
    CGContextDrawLayerInRect(context, rect, objectLayer); 

回答

2

你只是設置混合模式層的情況下,使圖像呈現在一個透明的背景柔和的光線混合模式(我認爲有渲染它的效果相同的頂部與正常混合模式)。

context的混合模式仍然設置爲正常,所以圖層(已渲染)將以該模式呈現。混合模式不會跨越上下文邊界。

+0

非常感謝,我解決了這個問題。 –