我是一名初学者,在iphone上进行绘画应用。如何在UIImageView上绘制喷枪?
为我的iPhone应用程序称为喷枪......
将喷上的UIImageView添加新工具。任何人都可以帮助我解决如何使用它。
我是一名初学者,在iphone上进行绘画应用。如何在UIImageView上绘制喷枪?
为我的iPhone应用程序称为喷枪......
将喷上的UIImageView添加新工具。任何人都可以帮助我解决如何使用它。
我想你可能在寻找CGContextBeginPath
及其相关功能。我不太确定如何定义一个新的笔划,但我想它可以用类似[UIColor colorFromImage:myImage]
的东西来处理。你应该看看Quartz 2D,试着看看here。
/托马斯
谢谢托马斯..... 有没有什么方法可以像粉笔画线。 – kiran 2010-08-05 10:54:36
这不会是在公园散步。您应该可以使用Quartz 2D API以某种方式制作自定义笔(笔画)。如果你无法在API中找到这个功能,我最好的猜测就是你可以加载一个图像(白色的粉笔),并在用户触摸图像时不断将其绘制到图像上。您将不得不在UIResponder上使用'touchesBegan:withEvent:',或者您可以制作一个手势识别器:http://developer.apple.com/iphone/library/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/GestureRecognizers/GestureRecognizers。 HTML – 2010-08-07 00:44:56
感谢......托马斯.... – kiran 2010-08-07 15:23:08
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();
}
你说的粉笔线是什么意思? – Plumenator 2010-08-05 07:20:19
感谢plumenator重播.... 其实我想在我的UIImageView上画画笔... – kiran 2010-08-05 07:24:38