CGContextAddLines和CGContextAddLineToPoint在线条半透明时候的区别
這兩種都可以用來畫線,前一種將整條線加入后畫出,后一種對每個點進行和前一個點的連線。
sample1-(void)drawLine:(YJLines?*)line{
????int?count = [line.points?count];
????CGPoint?addLines[count];
????for?(int?j=0; j< [line.points?count]; j++)?
????{
????????CGPoint?point =?CGPointFromString((NSString?*)[line.points?objectAtIndex:j]);
????????addLines[j].x?= point.x;
????????addLines[j].y?= point.y;
????}
????CGContextRef?context =?UIGraphicsGetCurrentContext();
????CGContextSetLineJoin(context,?kCGLineJoinRound);
????CGContextSetLineCap(context ,?kCGLineCapRound);
????CGContextSetBlendMode(context,?kCGBlendModeNormal);
????CGContextBeginPath(context);
????CGContextAddLines(context, addLines, count);
????CGContextSetLineWidth(context, line.lineWidth);
????CGContextSetAlpha(context, line.lineAlpha);
????CGContextSetStrokeColorWithColor(context, line.lineColor.CGColor);
????CGContextStrokePath(context);
}
sample2:- (void) contextDrawFrom: (CGPoint)last toPoint:(CGPoint)current withLine:(YJLines?*)ln {
????CGContextRef?context =?UIGraphicsGetCurrentContext();
//????CGContextSetMiterLimit(context, 0.5);
????CGContextSetLineJoin(context,?kCGLineJoinRound);
????CGContextSetLineCap(context ,?kCGLineCapRound);
????CGContextSetBlendMode(context,?kCGBlendModeNormal);
????CGContextBeginPath(context);
????CGContextMoveToPoint(context, last.x, last.y);
????CGContextAddLineToPoint(context, current.x, current.y);
????CGContextSetLineWidth(context, ln.lineWidth);
????CGContextSetAlpha(context, ln.lineAlpha);
????CGContextSetStrokeColorWithColor(context, ln.lineColor.CGColor);
????CGContextStrokePath(context);
}
AddLineToPoint實現方式在線條alpha為1,即不透明的時候和AddLines一樣,而且是實時畫線。 但是當線條半透明的時候,AddLines在一條線自身重疊時不會透明度重疊。 而AddLineToPoint卻會導致透明度重疊,且move touch的點出也會出現透明度重疊,會顯示成點和點之間透明度正確,點上不透明的問題。轉載于:https://www.cnblogs.com/pengyingh/articles/2403225.html
總結
以上是生活随笔為你收集整理的CGContextAddLines和CGContextAddLineToPoint在线条半透明时候的区别的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [转帖][攻防测试工具]系统监控必备工具
- 下一篇: 微信公众平台新增语义理解接口