CGContextAddLines和CGContextAddLineToPoint在线条半透明时候的区别
2014-11-20 14:52
387 查看
这两种都可以用来画线,前一种将整条线加入后画出,后一种对每个点进行和前一个点的连线。
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的点出也会出现透明度重叠,会显示成点和点之间透明度正确,点上不透明的问题。
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的点出也会出现透明度重叠,会显示成点和点之间透明度正确,点上不透明的问题。
相关文章推荐
- CGContextAddLines和CGContextAddLineToPoint在线条半透明时候的区别
- iOS绘图系列二:画直线 CGContextMoveToPoint,CGContextAddLineToPoint,CGContextAddLines,
- iOS绘图系列二:画直线 CGContextMoveToPoint,CGContextAddLineToPoint,CGContextAddLines,
- iOS: CGContext的函数CGContextAddLineToPoint
- iOS - CGContextAddLineToPoint 绘图崩溃:
- iOS绘图系列三:画弧线CGContextAddArc ,CGContextAddArcToPoint,CGContextAddCurveToPoint,UIBezierPath
- CGCONTEXTADDCURVETOPOINT 的深入理解
- iOS: CGContext的函数CGContextAddQuadCurveToPoint
- CGContextMoveToPoint与CGContextAddLineToPoint详解
- CGContextAddArc 和 CGContextAddArcToPoint 区别
- CGContextAddArc 和 CGContextAddArcToPoint 区别
- CGContextAddArc 和 CGContextAddArcToPoint 区别
- 打包exe的时候出现Unable to open this project because the add-on software
- How to upload file to SharePoint via commandline?
- 详细解析IOS中的CGContextAddArcToPoint方法的使用
- 详细解析IOS中的CGContextAddArcToPoint方法的使用
- IOS CGContextSetLineWidth无法设置1像素线宽?
- 详细解析IOS中的CGContextAddArcToPoint方法的使用
- CGContextAddArcToPoint与CGContextAddArc