问题描述
我想重写Apple源代码GLPaint应用程序,但不像示例一样使用OpenGL,而是要使用Core Graphics库.但是我坚持显示GLPaint这样的纹理.
这是我在Core Graphics中的代码:
---但我收到以下结果:
---我想得到这个结果:
我的代码错误吗?有人可以帮助我吗?非常感谢.
如果您不想要图案,请不要将带有图案图像的颜色设置为笔触颜色.
代替
UIImage * image = [UIImage imageNamed:@"Particle.png"];
UIColor * color = [UIColor colorWithPatternImage:image];
就做
UIColor *color = [UIColor blackColor];
I would like to rewrite the Apple source code, GLPaint application, but not using OpenGL like the example, I would like to use Core Graphics library. But I stuck in displaying the texture like GLPaint.
This is my code in Core Graphics:
- (void) drawLineFromPoint: (CGPoint) fromPoint toPoint: (CGPoint) toPoint {
UIGraphicsBeginImageContext(self.frame.size);
CGContextRef context = 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(context, kCGLineCapRound);
CGContextSetLineWidth(context, 5.0);
CGContextBeginPath(context);
CGContextMoveToPoint(context, fromPoint.x, fromPoint.y);
CGContextAddLineToPoint(context, toPoint.x, toPoint.y);
CGContextStrokePath(context);
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
--- But I receive this result:
--- I would like to have this result:
Does my code wrong? Any one can help me on this? Thank you very much.
If you don't want the pattern, don't set a colour with a pattern image as your stroke colour.
Instead of
UIImage * image = [UIImage imageNamed:@"Particle.png"];
UIColor * color = [UIColor colorWithPatternImage:image];
Just do
UIColor *color = [UIColor blackColor];
这篇关于iPhone:使用Core Graphics重写GLPaint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!