У меня есть приложение для iOS с функцией типа книжки-раскраски. Код, который я использую, работает для раскраски. При полной непрозрачности качество линии выглядит хорошо, но при более низкой непрозрачности вы можете видеть отдельные точки кисти.
Код:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
pointCurrent = [touch locationInView:self.view];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint pointNext = [touch locationInView:self.view];
UIGraphicsBeginImageContext(img.frame.size);
// UIGraphicsBeginImageContext(img2.frame.size);
[img.image drawInRect:CGRectMake(0, 0, img.frame.size.width, img.frame.size.height)];
// [img2.image drawInRect:CGRectMake(0, 0, img2.frame.size.width, img2.frame.size.height)];
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), brush);
/// CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), a, b, c, d);
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), pointCurrent.x, pointCurrent.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), pointNext.x, pointNext.y);
CGContextSetLineCap(UIGraphicsGetCurrentContext(),kCGLineCapRound);
CGContextStrokePath(UIGraphicsGetCurrentContext());
img.image = UIGraphicsGetImageFromCurrentImageContext();
// img2.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
pointCurrent = pointNext;
}
результат:
![enter image description here](https://i.stack.imgur.com/TUOQP.png)