首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用CGContextRef绘图

使用CGContextRef绘图
EN

Stack Overflow用户
提问于 2012-01-03 17:09:52
回答 1查看 3.8K关注 0票数 4

我正在尝试创建一个我可以在其中编写的应用程序。通过使用CGContextRef,我已经在这方面取得了进展。我写了下面的代码。

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-04 12:12:42

我终于破解了它。你必须为这个设置混合模式,下面是代码

代码语言:javascript
复制
 CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeCopy);
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8709952

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档