Why obj2 not blend with obj1 but without use CGLayer it works fine,same problem with CGContextDrawLayerAtPoint,Does CGLayer not support CGContextSetBlendMode??

    //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);
有帮助吗?

解决方案

You're only setting the blend mode within the layer's context, so the image is rendered on top of a transparent background with the soft light blend mode (which I think has the same effect as rendering it with the normal blend mode).

The blend mode of context is still set to normal, so the layer (which is already rendered) will be rendered with that mode. Blend modes do not cross context boundaries.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top