0
다음 코드를 사용하여 아이폰에 페인트 브러시를 만듭니다.아이폰에 페인트 브러시를 그리는 동안 라인에서 점들을 제거하는 방법?
@interface Canvas : UIImageView {
CGPoint location;
}
@property CGPoint location;
.m file
@synthesize location;
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
self.location = [touch locationInView:self];
}
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint currentLocation = [touch locationInView:self];
UIGraphicsBeginImageContext(self.frame.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
//CGContextSetBlendMode(ctx, kCGBlendModeOverlay);
[self.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
CGContextSetLineCap(ctx, kCGLineCapRound);
CGContextSetBlendMode(ctx, kCGBlendModeNormal);
CGContextSetLineWidth(ctx, 5.0);
CGContextSetRGBStrokeColor(ctx, 1.0, 0.0, 0.0, 1.0);
//CGContextSetBlendMode(ctx, kCGBlendModeOverlay);
CGContextBeginPath(ctx);
CGContextMoveToPoint(ctx, location.x, location.y);
CGContextAddLineToPoint(ctx, currentLocation.x, currentLocation.y);
CGContextStrokePath(ctx);
self.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
location = currentLocation;
}
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint currentLocation = [touch locationInView:self];
UIGraphicsBeginImageContext(self.frame.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
// CGContextSetBlendMode(ctx, kCGBlendModeOverlay);
[self.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
CGContextSetBlendMode(ctx, kCGBlendModeNormal);
CGContextSetLineCap(ctx, kCGLineCapRound);
CGContextSetLineWidth(ctx, 5.0);
CGContextSetRGBStrokeColor(ctx, 1.0, 0.0, 0.0, 1.0);
CGContextBeginPath(ctx);
CGContextMoveToPoint(ctx, location.x, location.y);
CGContextAddLineToPoint(ctx, currentLocation.x, currentLocation.y);
CGContextStrokePath(ctx);
self.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
location = currentLocation;
}
그것은 작동하지만 drawn.i 그 점을 제거하려면 부드러운 직선 line.How 내가 이것을 달성 할 수 원하는되고있는 줄에 일정한 거리 후 일부 도트가 그리는 동안이야?
정상으로 모드를 변경하더라도 동일한 이미지가 반복적으로 사용되는 것은 아닙니다. 또한 처음으로 – Bhoomi
의 결과 스크린 샷을 보여줍니다. 아마도 도움이됩니다. – calimarkus
그래서 투명 색상으로 그릴 경우에만 문제가 나타 납니까? 단색의 파란색 선이 괜찮은 것 같습니까? 당신은 터치의 모든 위치를 저장하고 모든 변경 사항에 대해 현재의 전체 라인을 새로 그릴 수 있습니다. – calimarkus