iphone:使用 Core Graphics 重写 GLPaint

标签 iphone ios opengl-es core-graphics

我想重写 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();
}

--- 但我收到了这个结果:

wrong result

--- 我想要这样的结果:

expected result

我的代码有错吗?任何人都可以帮助我吗?非常感谢。

最佳答案

如果您不想要图案,请不要将带有图案图像的颜色设置为描边颜色。

代替

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/

相关文章:

iphone - 横向模式 UIView.center 给出纵向模式坐标

opengl-es - gl_Color 是 WebGL 上未声明的标识符

ios - 我可以为 NSAttributedString 的大小||颜色设置动画吗?

android - 跨平台 openGLES?

iphone - 如何使用 cocos2d for iPhone 绘制实心圆

iphone - 使用 NSXMLParser 解析 XML 的最有效方法

iphone - NSPredicate 来查明实体的实例是否有父代?

ios - 我需要将图像保存在@1x、@2x、@3x 吗?

ios - 推送 View Controller ,但返回另一个

ios - 如何使用 objc 访问此数据集中的元素?