我正在尝试创建一个应用程序来进行写作。通过使用CGContextRef,我已经取得了一定的进展。以下是我的代码:
previousPoint2 = previousPoint1;
previousPoint1 = [touch previousLocationInView:m_secondaryDrawingImgeView];
currentPoint = [touch locationInView:m_secondaryDrawingImgeView];
// calculate mid point
CGPoint mid1 = [self midPoint:previousPoint1 :previousPoint2];
CGPoint mid2 =[self midPoint:currentPoint :previousPoint1];
UIGraphicsBeginImageContext(m_secondaryDrawingImgeView.frame.size);
[m_secondaryDrawingImgeView.image drawInRect:
CGRectMake(0, 0, m_secondaryDrawingImgeView.frame.size.width,
m_secondaryDrawingImgeView.frame.size.height)];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextMoveToPoint(context, mid1.x, mid1.y);
// Use QuadCurve is the key
CGContextAddQuadCurveToPoint(context,
previousPoint1.x, previousPoint1.y, mid2.x, mid2.y);
// NSMutableArray *arr = [NSMutableArray arrayWithObjects:mid1, nil]
// NSLog(@"%@",color);
CGContextSetStrokeColorWithColor(context, color.CGColor);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineWidth(context,m_width);
CGContextStrokePath(context);
m_secondaryDrawingImgeView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
当我将不透明度设置为我的颜色时,会显示出一些点,我想要去掉它们。这是我走的正确路径吗?有没有办法可以去掉这些点?
附上图片以获得更清晰的解释。写了这段代码后发生的情况如图1所示,而我想要的效果是图2。