gpt4 book ai didi

iphone - 有人可以告诉我如何创建一个 CGPattern 来用图像描画路径吗?

转载 作者:行者123 更新时间:2023-12-03 19:31:40 25 4
gpt4 key购买 nike

我想使用我拥有的 .png 绘制路径,但我只是不知道如何制作 CGPatternRef。

最佳答案

这是一个小片段

- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
[self patternMake2:rect context:context];
}
//-------------------------------------------------------------------
// patternMake2
//-------------------------------------------------------------------
void pattern2Callback (void *info, CGContextRef context) {
UIImage *image = [UIImage imageNamed:@"NavBarBg.png"];
CGImageRef imageRef = [image CGImage];
CGContextDrawImage(context, CGRectMake(0, 0, 320, 44), imageRef);
}


- (void)patternMake2:(CGRect)rect context:(CGContextRef)context
{
static const CGPatternCallbacks callbacks = { 0, &pattern2Callback, NULL };
//NSLog(@"rect: %f %f %f %f", rect.origin.x, rect.origin.x, rect.size.width, rect.size.height);
//CGContextSaveGState(context);
CGColorSpaceRef patternSpace = CGColorSpaceCreatePattern(NULL);
CGContextSetFillColorSpace(context, patternSpace);
CGColorSpaceRelease(patternSpace);
CGSize patternSize = CGSizeMake(315, 44);
CGPatternRef pattern = CGPatternCreate(NULL, self.bounds, CGAffineTransformIdentity, patternSize.width, patternSize.height, kCGPatternTilingConstantSpacing, true, &callbacks);
CGFloat alpha = 1;
CGContextSetFillPattern(context, pattern, &alpha);
CGPatternRelease(pattern);
CGContextFillRect(context, rect);
//CGContextRestoreGState(context);
}

关于iphone - 有人可以告诉我如何创建一个 CGPattern 来用图像描画路径吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2373028/

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