gpt4 book ai didi

iphone - 使用 Core Graphics 在 CGContextClip 之后绘制阴影

转载 作者:行者123 更新时间:2023-12-03 20:22:33 24 4
gpt4 key购买 nike

更新:我尝试实现 Peter 指定的方法,但得到了不正确的阴影。怎么了?

alt text http://grab.by/2XyP

CGContextSetShadowWithColor(c, CGSizeMake(4, 4), kAudioThumbShadowBlur, [[UAColor blackColor] CGColor]);
CGContextFillPath(c);

CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, minx, midy);
CGPathAddArcToPoint(path, NULL, minx, miny, midx, miny, kDefaultMargin);
CGPathAddArcToPoint(path, NULL, maxx, miny, maxx, midy, kDefaultMargin);
CGPathAddArcToPoint(path, NULL, maxx, maxy, midx, maxy, kDefaultMargin);
CGPathAddArcToPoint(path, NULL, minx, maxy, minx, midy, kDefaultMargin);
CGPathCloseSubpath(path);


// Fill and stroke the path
CGContextSaveGState(c);
CGContextAddPath(c, path);
CGContextClip(c);


myGradient = CGGradientCreateWithColorComponents(myColorspace, components, locations, 2);
CGContextDrawLinearGradient(c, myGradient, CGPointMake(minx,miny), CGPointMake(minx,maxy), 0);

CGContextAddPath(c, path);
CGPathRelease(path);
CGContextStrokePath(c);
CGContextRestoreGState(c);





原问题:我希望使用以下代码在 CoreGraphics 中制作的自定义圆形单元格项目的底部周围绘制自然的阴影:

...
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, minx, miny);
CGPathAddArcToPoint(path, NULL, minx, maxy, midx, maxy, kDefaultMargin);
CGPathAddArcToPoint(path, NULL, maxx, maxy, maxx, miny, kDefaultMargin);
CGPathAddLineToPoint(path, NULL, maxx, miny);
CGPathAddLineToPoint(path, NULL, minx, miny);
CGPathCloseSubpath(path);

// Fill and stroke the path
CGContextSaveGState(c);
CGContextAddPath(c, path);
CGContextClip(c);

myGradient = CGGradientCreateWithColorComponents(myColorspace, components, locations, 2);
CGContextDrawLinearGradient(c, myGradient, CGPointMake(minx,miny), CGPointMake(minx,maxy), 0);

CGContextAddPath(c, path);
CGPathRelease(path);
CGContextStrokePath(c);
CGContextRestoreGState(c);
...

我想在渐变填充之前或之后在该路径的外部应用阴影。这样做的最佳方法是什么?

最佳答案

渐变绘制不算作填充,因此,首先设置阴影并进行纯色填充。然后,使用渐变和剪切描边在纯色填充上绘制。

关于iphone - 使用 Core Graphics 在 CGContextClip 之后绘制阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2413756/

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