Compound colors: CALayer and blend mode on iPhone

I am trying to use the main image on iphone. I can combine my colors with quartz to draw a uiview, but I want to split each component into CALayer (UIview consumes more resources).

So, I have a white mask that I want to use to filter out the background bitmap, and I want to try a different blending mode. Unfortunately, layers only “add” their colors.

Here is my code:

 @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 

And here is the main drawrect view drawrect , 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]; } 

Something is wrong?

+6
iphone calayer mode blend
source share
3 answers

I managed to get an effect on the layout of several CALayers by displaying them directly in the graphical context of the UIView.

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

By the way, I did not add layers as sub-layers of the presentation level (I never called it [myView.layer addSublayer: myLayer])

+7
source share

This method does not seem to be a drawback of Core Animation, because layers are previously passed to image contexts. Core Image is used to filter in real time (during animation and much more) these images against background layers and their images. Thus, for this ability, CALayer layout properties are used, which are not available on iPhone / iOS (yet) due to the Core Image requirement.

OpenGL can do this for us in our situation, however =)

edit: set the blend mode from CGContext to -drawInContext: and -drawLayer: inContext: of course, it has an effect with what was already displayed or represented in the image of this context. (when set before something was displayed in context (image), this is the effect of blending with full black or full white (I'm not sure if =)

+3
source share

Not at all ... I think it's easier to use opengl for this, because it does not seem to be implemented in CA yet.

+1
source share

All Articles