How do I draw lines with alpha < 1 in quartz 2d

前端 未结 4 1400
执笔经年
执笔经年 2020-12-20 01:12

No doubt this might be a duplicate question but I am not able to get proper solution from any post here. So I am posting this as new post with a hope that I get some solutio

4条回答
  •  有刺的猬
    2020-12-20 01:51

    Hie..

    This is my final solution.. I am now drawing lines on drawRect event and drawing the entire line at a time as a path.. This creates opacity to retain and now no line caps drawn in between..

    No doubt this is the trick that is working since I am drawing on every touch and this works..

    - (void)drawRect:(CGRect)rect {
    for (int j=0; j<[pathArray count]; j++) 
    {
        context = UIGraphicsGetCurrentContext();
        NSMutableDictionary *tmp=[pathArray objectAtIndex:j];
        NSMutableArray *currentPath=[tmp objectForKey:@"path"];
        for (int i=0; i<[currentPath count]; i++) 
        {
            CGPoint mid1 = [[self midPoint:[currentPath objectAtIndex:i+1]  :[currentPath objectAtIndex:i]] CGPointValue]; 
            CGPoint mid2 = [[self midPoint:[currentPath objectAtIndex:i+2] :[currentPath objectAtIndex:i+1]] CGPointValue];
            CGContextMoveToPoint(context, mid1.x, mid1.y);
            CGContextAddQuadCurveToPoint(context, [[currentPath objectAtIndex:i+1] CGPointValue].x, [[currentPath objectAtIndex:i+1] CGPointValue].y, mid2.x, mid2.y); 
            CGContextSetShadow(context, CGSizeMake(-2, -2), 3);
            CGContextSetAlpha(context, [[tmp objectForKey: @"opacity"] floatValue]);    
            CGContextSetLineCap(context, kCGLineCapRound);
            CGContextSetStrokeColorWithColor(context,[[tmp objectForKey: @"Color"] CGColor]);               
            CGContextSetLineWidth(context, [[tmp objectForKey: @"width"] floatValue]);              
            i+=2;
        }   
        CGContextStrokePath(context);
    
    }
    }
    

提交回复
热议问题