0
我正在使用以下代码在iphone中创建画笔。如何在iphone中绘制画笔时从线上删除点?
@interface Canvas : UIImageView {
CGPoint location;
}
@property CGPoint location;
.m file
@synthesize location;
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
self.location = [touch locationInView:self];
}
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint currentLocation = [touch locationInView:self];
UIGraphicsBeginImageContext(self.frame.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
//CGContextSetBlendMode(ctx, kCGBlendModeOverlay);
[self.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
CGContextSetLineCap(ctx, kCGLineCapRound);
CGContextSetBlendMode(ctx, kCGBlendModeNormal);
CGContextSetLineWidth(ctx, 5.0);
CGContextSetRGBStrokeColor(ctx, 1.0, 0.0, 0.0, 1.0);
//CGContextSetBlendMode(ctx, kCGBlendModeOverlay);
CGContextBeginPath(ctx);
CGContextMoveToPoint(ctx, location.x, location.y);
CGContextAddLineToPoint(ctx, currentLocation.x, currentLocation.y);
CGContextStrokePath(ctx);
self.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
location = currentLocation;
}
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint currentLocation = [touch locationInView:self];
UIGraphicsBeginImageContext(self.frame.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
// CGContextSetBlendMode(ctx, kCGBlendModeOverlay);
[self.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
CGContextSetBlendMode(ctx, kCGBlendModeNormal);
CGContextSetLineCap(ctx, kCGLineCapRound);
CGContextSetLineWidth(ctx, 5.0);
CGContextSetRGBStrokeColor(ctx, 1.0, 0.0, 0.0, 1.0);
CGContextBeginPath(ctx);
CGContextMoveToPoint(ctx, location.x, location.y);
CGContextAddLineToPoint(ctx, currentLocation.x, currentLocation.y);
CGContextStrokePath(ctx);
self.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
location = currentLocation;
}
它的工作,但同时提请有一定的距离后,一些点在该行正在drawn.i要删除这些点,并希望顺利直line.How我可以做到这一点?
即使我改变模式以正常的效果come.that不是bcoz一次again.it使用同样的图像也谈到第一次 – Bhoomi 2012-04-19 15:17:17
告诉我们结果的截图..也许没有什么帮助。 – calimarkus 2012-04-19 15:52:18
所以只有在使用透明颜色绘制时才会出现该问题?坚实的蓝色线似乎是好的?您可以保存touchesmoved的所有位置,并在每次更改时重新绘制整个当前行。 – calimarkus 2012-04-20 19:54:16