小编Ali*_*Ali的帖子

复合颜色:iPhone上的CALayer和混合模式

我正试图在iphone上使用核心图像.我能够使用quartz来合成我的颜色以绘制uiview,但我想将每个组件分开CALayer(UIview消耗更多资源).

所以我有一个白色的面具我想用来过滤背景位图,我想尝试不同的混合模式.不幸的是,这些图层只是"添加"了它们的颜色.

这是我的代码:

@implementation WhiteLayerHelper

    - (void)drawLayer:(CALayer *)theLayer
            inContext:(CGContextRef)myContext
    {
        // draw a white overlay, with special blending and alpha values, so that the saturation can be animated
        CGContextSetBlendMode(myContext,kCGBlendModeSaturation);
        CGContextSetRGBFillColor(myContext,1.0,1.0,1.0,0.9);
        CGContextFillRect(myContext,[UIScreen mainScreen].bounds);

    }

@end
Run Code Online (Sandbox Code Playgroud)

这是drawrect我使用CALayer 的主视图代码:

- (void)drawRect:(CGRect)rect {
    //get the drawing context
    CGContextRef myContext = UIGraphicsGetCurrentContext();
    // draw the background
    [self fillContext:myContext withBounds:m_overlayRect withImage:m_currentImage];
    [whiteLayer renderInContext:myContext];

}
Run Code Online (Sandbox Code Playgroud)

有什么不对?

iphone blend mode calayer

6
推荐指数
3
解决办法
2万
查看次数

标签 统计

blend ×1

calayer ×1

iphone ×1

mode ×1