2011-08-26 2 views
-1

나는 이제 지우개 교차 어디서위한 삭제 기능을 가겠어요 어떻게Quartz2d 도면의 특정 지점에 대해 지우기 기능을 어떻게 수행 할 수 있습니까?

CGPoint currentPoint = CGPointMake(rascalImage.center.x, rascalImage.center.y); 
     currentPoint.y += 10; 


     UIGraphicsBeginImageContext(self.view.frame.size); 
     [drawingView.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
     CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); 
     CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0); 
     CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0); 
     CGContextBeginPath(UIGraphicsGetCurrentContext()); 
     CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y); 
     CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y); 
     CGContextStrokePath(UIGraphicsGetCurrentContext()); 
     drawingView.image = UIGraphicsGetImageFromCurrentImageContext(); 
     UIGraphicsEndImageContext(); 

     lastPoint = currentPoint; 

quartz2d에서 선을 그리는이 코드를 사용? 나는 지우개가 만지는 선에서 특정 지점을 지워야 만한다는 것을 알고있다. 나는 이것을 어떻게하는지 모른다. 그래서 도와주세요!

답변

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

     CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); 
     CGContextSetLineWidth(UIGraphicsGetCurrentContext(),lineWidth); 
     CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear); 

     CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red, green, blue, 1.0); 
     CGContextBeginPath(UIGraphicsGetCurrentContext()); 
     CGContextSetShouldAntialias(UIGraphicsGetCurrentContext(), YES); 

     CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint1.x, lastPoint1.y); 
     CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y); 
     CGContextStrokePath(UIGraphicsGetCurrentContext()); 
     imgBlankView.image = UIGraphicsGetImageFromCurrentImageContext(); 

     UIGraphicsEndImageContext(); 
+0

안녕하세요 @CrazyDeveloper, 코드를 사용해 보았습니다. 작동하지만 일련의 실행 취소 및 다시 실행을 수행 할 때 그려야한다고 가정합니다. 일부 라인을 누른 다음 완전히 다시 실행하고 완전히 다시 실행하고 지우기를 시도, 그것은 전체 rect을 지우는 방법,이 문제를 해결하는 방법, 내가 이것에 대한 다른 게시물을 만들었습니다보세요 http://stackoverflow.com/questions/11502320/지우개 - 작동하지 않는 - ios-drawing – Ranjit

0

단색 배경에 그리지 않는다고 가정합니까? 그렇다면 동일한 함수를 사용하여 대조되는 선 위에 배경색의 선을 그립니다.

하지만 배경이 복잡하기 때문에 그래픽 컨텍스트를 끝내고 그린 선에서 UIImage를 가져 오면 선만 지울 수 없습니다. 복잡한 드로잉 응용 프로그램을 만드는 경우 드로잉 환경을 만들기 위해 레이어를 사용하고 다른 레이어 위에 하나의 레이어를 "쌓아 올리는"방법을 제안합니다.

또한 체크 아웃이 게시물 : How to erase some portion of a UIImageView's image on iOS?

+0

는 아직이 밖으로 시도 할 기회가 있었나요? 모든 질문, 의견 등? 내가 너의 질문에 대답 했니? – James

+0

kClearBlendMode를 블렌드 모드 또는 그와 유사한 것으로 사용하여 늦게 대답 해 주셔서 죄송합니다. – Aspyn