2013-01-25 4 views
1

UIImage (브러시 응용 프로그램과 같은) 위에 몇 줄을 그려 넣으면 고무처럼 지워야합니다. 이 사이트와 Google에서 많은 검색을했는데 일부 코드를 시도했지만 올바른 해결책을 찾을 수 없었습니다. [UIColor clearColor]와 컨텍스트의Clear CGContext Lines

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 

    if(isDrawing == YES) { 

     UITouch *touch = [touches anyObject]; 
     CGPoint currentPoint = [touch locationInView:mainImageView.superview]; 

     UIGraphicsBeginImageContext(mainImageView.frame.size); 
     [mainImageView.image drawInRect:CGRectMake(0, 0, mainImageView.frame.size.width, mainImageView.frame.size.height)]; 

     CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); 
     CGContextSetLineWidth(UIGraphicsGetCurrentContext(), dimension); 

     const CGFloat *components = CGColorGetComponents([color CGColor]); 
     CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), components[0], components[1], components[2], components[3]); 

     CGContextBeginPath(UIGraphicsGetCurrentContext()); 
     CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y); 
     CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y); 
     CGContextStrokePath(UIGraphicsGetCurrentContext()); 

     mainImageView.image = UIGraphicsGetImageFromCurrentImageContext(); 
     UIGraphicsEndImageContext(); 

     lastPoint = currentPoint; 

    } else { 
     //Clear current line (like a rubber would do) 
    } 
} 

답변

0

채우기 원하는 부분 : 은 여기 작성하는 데 사용하는 코드입니다.

+0

미안합니다. –

2

이 시나리오에서는 [UIColor clearColor]이 작동하지 않으므로 CGContextClearRect(context,rect);을 사용하여 영역을 지우십시오! 올바른 접근가 베지 경로를 사용

0

:

  • 두께를 갖는다 ("스트로크"를 사용 ..의 drawRect 우리가 그리는 것이다 .. 그려지지 않는 사실이지만)

    • 모든 도면을 기록, 색상 등등 ...
    • 은 배경을 다시 나타나게됩니다 setNeedsDisplay를 ("removeAllPoints"을 사용하여)을 삭제하고 호출

    보기에 효과적으로립니다.

    다른 도구를 사용하여 작성한 경로를 고무로 제거하려면 (연필 도구를 사용하여 파란색으로 작성하고 고무 도구로 파란색 선을 지우고 다시 배경을 나타 내기라고 말하면됩니다) "containsPoint :"는 일부 점을 제거하여 베 지어 경로를 형성합니다.

    우리는 이렇게했습니다.

    베지에 경로를 사용하는 것은 간단하지 않지만 매우 흥미로운 .. ..