我想重写 Apple 源代码,GLPaint 应用程序,但不像示例那样使用 OpenGL,我想使用 Core Graphics 库。但我坚持像 GLPaint 一样显示纹理。
这是我在 Core Graphics 中的代码:
- (void) drawLineFromPoint: (CGPoint) fromPoint toPoint: (CGPoint) toPoint {
UIGraphicsBeginImageContext(self.frame.size);
CGContextRef 上下文 = UIGraphicsGetCurrentContext();
[drawImage.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
UIImage * image = [UIImage imageNamed:@"Particle.png"];
UIColor * color = [UIColor colorWithPatternImage:image];
CGContextSetStrokeColorWithColor(context, color.CGColor);
CGContextSetLineCap(上下文,kCGLineCapRound);
CGContextSetLineWidth(上下文, 5.0);
CGContextBeginPath(上下文);
CGContextMoveToPoint(上下文,fromPoint.x,fromPoint.y);
CGContextAddLineToPoint(上下文,toPoint.x,toPoint.y);
CGContextStrokePath(上下文);
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
--- 但我收到了这个结果:
--- 我想要这样的结果:
我的代码有错吗?任何人都可以帮助我吗?非常感谢。
最佳答案
如果您不想要图案,请不要将带有图案图像的颜色设置为描边颜色。
代替
UIImage * image = [UIImage imageNamed:@"Particle.png"];
UIColor * color = [UIColor colorWithPatternImage:image];
就这样
UIColor *color = [UIColor blackColor];
关于iphone:使用 Core Graphics 重写 GLPaint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6593566/