2009-09-05 7 views
1

두 개의 겹치는 이미지가 있습니다. 위 이미지의 일부를 지우면 특정 부분이 지워지고 기본 이미지가 나타납니다. 하지만 특정 부분을 삭제하면 이미지의 지워진 부분을 다시 돌려줘야합니다.이미지 지우기 및 이미지 지우기

실행 취소 기능은 필요하지 않지만 지운 부분 만 표시됩니다. 는 touchesMoved 이벤트에

:

UIGraphicsBeginImageContext(frontImage.frame.size); 
[frontImage.image drawInRect:CGRectMake(0, 0, frontImage.frame.size.width, frontImage.frame.size.height)]; 
CGContextSetLineCap(UIGraphicsGetCurrentContext(),kCGImageAlphaNone); //kCGImageAlphaPremultipliedLast); 
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10); 
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1, 0, 0, 10); 
CGContextBeginPath(UIGraphicsGetCurrentContext()); 
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y); 
//this line code for erasing select the part of the image 
CGContextClearRect (UIGraphicsGetCurrentContext(), CGRectMake(lastPoint.x, lastPoint.y, 10, 10)); 
//End the code 
CGContextStrokePath(UIGraphicsGetCurrentContext()); 
frontImage.image = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 

이 친절 문제에 대해 도와 여기

내가 위의 이미지를 삭제하기 위해 사용하고있는 코드입니다.

미리

이미지의 그 부분에 대한 알파를 수정하지 않는 이유를 대신 소거

답변

1

에 여러분 모두 감사합니다. 그런 다음 다시 되돌리려면 알파 백을 수정하십시오.

그렇지 않으면 하단 이미지가 지워질 때 전체 상단 이미지를 복원해야합니다.

+0

이미지의 해당 부분의 알파를 수정하는 것이 좋습니다. 그러나 이미지의 선택된 부분이나 접촉 한 부분의 알파 값을 어떻게 수정할 수 있습니까? 어떻게하는지 알고 계십니까? 친절하게 도와주세요. – milanjansari

+0

이미지 또는 레이어에서 비트 맵 가져 오기 (http://developer.apple.com/mac/library/qa/qa2007/qa1509.html 참조). 비트 맵을 빠르게 실행하여 터치 포인트를 찾습니다. 그런 다음 주변 픽셀의 알파 값으로 재생합니다. – mahboudz

+0

잠깐, 적절한 블렌드 모드로 다른 이미지를 맨 위에 그려서 필요한 알파를 제공하는 것처럼 더 좋은 방법이있을 것입니다. – mahboudz