繁体   English   中英

如何在UIImageView上绘制喷枪?

[英]how to draw airbrush on UIImageView?

我是iphone上绘画应用程序的初学者。

为我的iPhone应用程序添加称为喷枪的新工具...

它将喷在UIImageView上。 谁能帮我解决该问题。

Logic for air brush.........

- (UIBezierPath *)pathFromPoint:(CGPoint)start toPoint:(CGPoint)end {

    CGFloat lineWidth=10;
    redrawRect = CGRectMake(end.x-lineWidth,end.y-lineWidth,lineWidth*2,lineWidth*2);
    UIBezierPath *bezierPath = [UIBezierPath bezierPath];
    UIBezierPath *circle = [UIBezierPath bezierPathWithOvalInRect:redrawRect];
    NSInteger i, x, y;

    NSInteger modNumber =4*(int)lineWidth;
    for (i = 0; i < (lineWidth*lineWidth)/2; i++) {
        do {
            x = (random() % modNumber)+end.x - 2*lineWidth;
            y = (random() % modNumber)+end.y - 2*lineWidth;
        } while (![circle containsPoint:CGPointMake(x,y)]);

        [bezierPath appendPath:[UIBezierPath bezierPathWithRect:CGRectMake(x,y,0.5,0.5)]];
    }
    return bezierPath;
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];   
    currentPoint = [touch locationInView:self.view];
    currentPoint.y -=20;
    [self drawCircle];
}
-(void)drawCircle{
    UIGraphicsBeginImageContext(self.drawImage.frame.size);
    [drawImage.image drawInRect:CGRectMake(0,0, drawImage.frame.size.width, drawImage.frame.size.height)]; //originally self.frame.size.width, self.frame.size.height)];
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(),10);
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.0, 0.0, 1.0);
    UIBezierPath *path=[self pathFromPoint:currentPoint 
                                   toPoint:currentPoint];
    [path stroke];
    lastPoint = currentPoint;
    CGContextStrokePath(UIGraphicsGetCurrentContext());
    CGContextFlush(UIGraphicsGetCurrentContext());
    drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
}

我认为您可能正在寻找CGContextBeginPath及其相关功能。 我不太确定如何定义一个新笔触,但是我想可以使用[UIColor colorFromImage:myImage]类的东西来处理它。 您应该查看Quartz 2D,尝试在此处查看

/托马斯

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM