【问题标题】:Why CGLayers are not blending?为什么 CGLayers 不混合?
【发布时间】:2012-05-02 11:13:20
【问题描述】:

为什么 obj2 不与 obj1 混合,但不使用 CGLayer 可以正常工作,与 CGContextDrawLayerAtPoint 相同的问题,CGLayer 不支持 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);

【问题讨论】:

    标签: objective-c cocoa-touch drawrect cgcontext cglayer


    【解决方案1】:

    您只是在图层的上下文中设置混合模式,因此图像使用柔光混合模式渲染在透明背景之上(我认为与渲染具有相同的效果使用正常的混合模式)。

    context 的混合模式仍设置为正常,因此图层(已渲染)将以该模式渲染。混合模式不跨越上下文边界。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-21
      • 1970-01-01
      • 1970-01-01
      • 2019-03-25
      • 1970-01-01
      • 1970-01-01
      • 2011-11-14
      相关资源
      最近更新 更多