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-to-er-line-from-image-by-painting) – jrturton

+0

예이 링크는 당신을 도울 수 http : // stackoverflow. co.kr/questions/3863931/수동 삭제 옵션 - ipad-painting-application-by-quartz/12797513 # comment19041354_12797513 –

답변

10

투명도로 바뀌는 선을 그려서 픽셀을 지우려면 획 색상을 완전히 투명하게 유지해야하며 혼합 모드를 kCGBlendModeCopy으로 변경해야합니다 (기본 혼합 모드에서는 물론 완전히 투명한 획 색상은 효과가 없습니다.)

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

그 후, 당신은 당신이 당신의 코드에서하고있는 것처럼은 "지우개"라인 (CGContextMoveToPoint, CGContextAddLineToPoint, CGContextStrokePath) 코코아 [의

+0

정말 고마워요 ... – CrazyDev

+0

멋진 형제 님 ... 그 일을 완벽하게 ... 고마워요 ... – sohil

+0

예 잘하고 ... 나는 신속하게 노력 ... 알았어. –