本文介绍了复合颜色:iPhone上的CALayer和混合模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to use core image on the iphone. I'm able to composite my colors using quartz to draw an uiview, but I want to separate each component into CALayer (UIview consume more resources).

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

So I have a white mask I want to use to filter a background bitmap, and I want to try different blending mode. Unfortunately, the layers are only "adding" their colors.

这是我的代码:

@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

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

And here is the main view drawrect code, where I use my 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];

}

有什么问题吗?

推荐答案

我设法通过直接将它们绘制到UIView的图形上下文来获得合成多个CALayers的效果。

I managed to get the affect of compositing multiple CALayers by drawing them directly into a UIView's graphics context.

-(void)drawRect:(CGRect)rect {
 CGContextRef c = UIGraphicsGetCurrentContext();
 CGContextSetBlendMode(c, kCGBlendModeDifference);
 [myLayer drawInContext:c];
}

BTW,我没有将图层添加为视图图层的子图层(我永远不会调用[myView.layer addSublayer:myLayer])

BTW, I did not add the layers as sublayers of the view's layer (that is I never called [myView.layer addSublayer:myLayer])

这篇关于复合颜色:iPhone上的CALayer和混合模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 10:52