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的點出也會出現透明度重疊,會顯示成點和點之間透明度正確,點上不透明的問題。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM