나는 CGContext에이 완전히 모든 정보가 삭제됩니다cgcontext에서 그려진 경로를 가볍게 지우는 방법은 무엇입니까?
UIImageView *maskImgView = [self.view viewWithTag:K_MASKIMG];
UIGraphicsBeginImageContext(maskImgView.image.size);
[maskImgView.image drawAtPoint:CGPointMake(0,0)];
float alp = 0.5;
UIImage *oriBrush = [UIImage imageNamed:_brushName];
//sets the style for the endpoints of lines drawn in a graphics context
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGFloat eraseSize = oriBrush.size.width*_brushSize/_zoomCurrentFactor;
CGContextSetLineCap(ctx, kCGLineCapRound);
CGContextSetLineJoin(ctx, kCGLineJoinRound);
CGContextSetLineWidth(ctx,eraseSize);
CGContextSetRGBStrokeColor(ctx, 1, 1, 1, alp);
CGContextSetBlendMode(ctx, kCGBlendModeClear);
CGContextBeginPath(ctx);
CGContextMoveToPoint(ctx, lastPoint.x,lastPoint.y);
CGPoint vector = CGPointMake(currentPoint.x - lastPoint.x, currentPoint.y - lastPoint.y);
CGFloat distance = hypotf(vector.x, vector.y);
vector.x /= distance;
vector.y /= distance;
for (CGFloat i = 0; i < distance; i += 1.0f) {
CGPoint p = CGPointMake(lastPoint.x + i * vector.x, lastPoint.y + i * vector.y);
CGContextAddLineToPoint(ctx, p.x, p.y);
}
CGContextStrokePath(ctx);
maskImgView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastPoint = currentPoint;
문제를 삭제 도면을 구현할 수 있었다. 이 함수에서 설정된 알파 (CGContextSetRGBStrokeColor(ctx, 1, 1, 1, alp);
)는 완전히 무시 된 것 같습니다.
가볍게 지우고 반복적으로 지우고 싶다면 그림을 완전히 제거합니다.
아이디어가 있으십니까?
편집는 : 요청에 따라,이 코드에 대한 자세한 내용을 추가 ALP는 = _brushAlpha이의 ViewController 클래스에 delcared 속성입니다. 범위는 0.1 ~ 1.0입니다. 테스트 할 때 0.5로 설정했습니다. 이 드로잉 코드는 팬 제스처 인식기 (상태 변경)에 의해 트리거됩니다. 기본적으로 손가락을 따라갑니다 (손가락으로 그리거나 지우기).
'alp'의 가치가 무엇인지 관객에게 친절하게 이야기 해 주시겠습니까? '_brushAlpha'는 무엇입니까? 그러나이 도면 코드는 어디에 있습니까? –
Ok 코드에 대한 자세한 내용을 추가했습니다. – GeneCode