开发者

iphone: rewrite GLPaint using Core Graphics

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 = UIGraphicsGetImageFromCur开发者_Go百科rentImageContext();
    UIGraphicsEndImageContext();
}

--- But I receive this result:

iphone: rewrite GLPaint using Core Graphics

--- I would like to have this result:

iphone: rewrite GLPaint using Core Graphics

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];


Kindly make sure you have the Particle.png added to the project. Also check the constants kBrushScale and kPalette* in GLPaint code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜