我需要在图像视图中绘制平滑曲线时混合两种颜色,如同 - 红色和蓝色的混合应仅在两种颜色的交点处产生紫色(红色+黄色=橙色,黄色+蓝色=绿色) 。我尝试使用coregraphics的混合模式,但没有用。任何人都可以帮助我吗?
-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
self.prePreviousPoint = self.previousPoint;
self.previousPoint = [touch previousLocationInView:self];
CGPoint currentPoint = [touch locationInView:self];
CGPoint mid1 = [self calculateMidPointForPoint:self.previousPoint andPoint:self.prePreviousPoint];
CGPoint mid2 = [self calculateMidPointForPoint:currentPoint andPoint:self.previousPoint];
UIGraphicsBeginImageContext(self.drawImageView.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[currentColor setStroke];
CGContextSetBlendMode(context, kCGBlendModeMultiply);
CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(), TRUE);
CGContextSetShouldAntialias(UIGraphicsGetCurrentContext(), TRUE);
[self.drawImageView.image drawInRect:CGRectMake(0, 0, self.drawImageView.frame.size.width, self.drawImageView.frame.size.height)];
CGContextMoveToPoint(context, mid1.x, mid1.y);
// // Use QuadCurve is the key
CGContextAddQuadCurveToPoint(context, self.previousPoint.x, self.previousPoint.y, mid2.x, mid2.y);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineWidth(context, self.lineWidth);
CGContextStrokePath(context);
self.drawImageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}