Iphone 使用CGContextRef绘制

Iphone 使用CGContextRef绘制,iphone,objective-c,ios5,Iphone,Objective C,Ios5,我正在尝试创建一个可以编写的应用程序。通过使用CGContextRef,我在这方面取得了进展。我已经编写了以下代码 previousPoint2 = previousPoint1; previousPoint1 = [touch previousLocationInView:m_secondaryDrawingImgeView]; currentPoint = [touch locationInView:m_secondaryDrawingImgeView]; // calculate mid

我正在尝试创建一个可以编写的应用程序。通过使用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();
当我将“不透明度”设置为我的颜色时,它会在一条直线上显示点,我要删除这些点

我走的路对吗? 有什么办法可以去掉这些点吗

附加图像以提高清晰度。写下这段代码后发生的事情是image-1,我想要的是image-2


我终于破解了它。您必须为此设置混合模式,以下是代码

 CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeCopy);

意思是你想让效果像第二张图片?可能对你有帮助。谢谢你的快速回复。但当我设置颜色的不透明度时,它也不起作用,它给了我相同的结果。是的,莎拉,我想让效果像第二张图片是的。你能告诉我,如果我想设置颜色的不透明度,我该如何设置?我正在用颜色设置alpha值。(rgba中的a)这很好。。现在勾选你的答案为正确,然后关闭帖子。嗯,你需要等到明天