Frage

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);
War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top