2011-12-05 3 views
0

を削除行描く:IOS:私のコードでは、別の行

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
mouseSwiped = YES; 

UITouch *touch = [touches anyObject]; 
CGPoint currentPoint = [touch locationInView:drawImage]; 

UIGraphicsBeginImageContext(drawImage.frame.size); 
[drawImage.image drawInRect:CGRectMake(0, 0, drawImage.frame.size.width, drawImage.frame.size.height)]; 
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); 
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10.0); 
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), r, g, b, a); 
CGContextBeginPath(UIGraphicsGetCurrentContext()); 
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y); 
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y); 
CGContextStrokePath(UIGraphicsGetCurrentContext()); 
drawImage.image = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

lastPoint = currentPoint; 

mouseMoved++; 

if (mouseMoved == 10) { 
    mouseMoved = 0; 
} 
} 

を私がdrawImageメソッドで線を描画することができるよ、私は、他の行を削​​除線を引くしたい場合は?描かれた他の線を消去する消しゴムとして。出来ますか?

+0

が重複する可能性を引き出すことができますすることにより、画像からラインを消去する方法絵画?](http://stackoverflow.com/questions/8317152/cocoa-how-to-erase-line-from-image-by-painting) – jrturton

+0

はいこのリンクはあなたを助けてくれる http:// stackoverflow。 com/questions/3863931 /手動で消去するオプションを追加するipad-painting-application-by-quartz/12797513#comment19041354_12797513 –

答えて

10

透明部分を置き換える線を描画してピクセルを消去する場合は、ストロークの色を完全に透明にする必要がありますが、ブレンドモードをkCGBlendModeCopyに変更する必要があります完全に透明なストロークカラーはもちろん効果がありません)。

CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0, 0, 0, 0); 
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeCopy); 

その後、あなたはあなたのコードスニペットでやっているだけのように「消しゴム」行(CGContextMoveToPointCGContextAddLineToPointCGContextStrokePath)ココア[の

+0

ありがとうございました... – CrazyDev

+0

ニースは..その仕事は完璧です...ありがとうございました... – sohil

+0

はいうまく働いています...私は迅速に試しました..得ました –

関連する問題