gpt4 book ai didi

iphone - 复合颜色: CALayer and blend mode on iPhone

转载 作者:行者123 更新时间:2023-12-03 18:42:16 25 4
gpt4 key购买 nike

我正在尝试在 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

这是主视图 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];

}

有什么问题吗?

最佳答案

通过将多个 CALayer 直接绘制到 UIView 的图形上下文中,我设法获得了合成多个 CALayer 的效果。

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

顺便说一句,我没有将图层添加为 View 图层的子图层(也就是说,我从未调用过 [myView.layer addSublayer:myLayer])

关于iphone - 复合颜色: CALayer and blend mode on iPhone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1658751/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com