iphone - 使用 CGContextRef 绘图

标签 iphone objective-c ios5

我正在尝试创建一个我可以编写的应用程序。通过使用 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

enter image description here enter image description here

最佳答案

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

 CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeCopy);

关于iphone - 使用 CGContextRef 绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8709952/

相关文章:

iphone - 如何使用相同类型的子对象计算自定义对象的深度?

iphone - 播放多个视频

iphone - iPhone ARKit 中的位置在一处重叠

ios - 当滑动到pop viewController时如何识别interactivePopGestureRecognizer是否成功进行?

iphone - Cocoa Touch 中的音调生成

iphone - MFMailComposer - 在邮件正文中嵌入可点击的链接?

iphone - 带有异常肥胖的 UISegmentedControl 的 UIToolbar

ios - 使用 Alamofire 的不可信证书。我已经尝试了所有我能找到的答案

ios 5 uiwebview 阴影

ios - 如何将iOS模拟器语言更改为瑞典语