Draw lines with Glow effect in iPad App

后端 未结 2 701
夕颜
夕颜 2021-01-22 17:44

I have integrate draw line in my application i have not used OpenGL or any other similar framework.

So now i want to give glow effect to their lines so how

相关标签:
2条回答
  • 2021-01-22 18:05
    -(void)drawRect:(CGRect)rect{
    
    [curImage drawAtPoint:CGPointMake(0, 0)];
    
     CGPoint mid1 = midPoint(previousPoint1, previousPoint2); 
    
     CGPoint mid2 = midPoint(currentPoint, previousPoint1);
    
        CGContextRef context = UIGraphicsGetCurrentContext(); 
    
        [self.layer renderInContext:context];
    
        CGContextMoveToPoint(context, mid1.x, mid1.y);
        // Use QuadCurve is the key
        CGContextAddQuadCurveToPoint(context, previousPoint1.x, previousPoint1.y, mid2.x, mid2.y); 
    
        CGContextSetLineCap(context, kCGLineCapRound);
        CGContextSetLineWidth(context, self.lineWidth);
        CGContextSetStrokeColorWithColor(context, self.lineColor.CGColor);
            //------------  Glow Lines ----------
    
        if (appDel.BrushType == 201) // (201 is glow brush type)
        {
            CGContextSetLineWidth(context, 7);
    
            CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
    
            CGFloat components[4]={appDel.R_color/255.0,appDel.G_color/255.0,appDel.B_color/255.0,1.0};
            CGColorRef color1 = CGColorCreate(space, components);
    
            CGContextSetShadowWithColor(context, CGSizeMake( 0.0, 0.0 ), 15, color1);
    
            CGContextStrokePath(UIGraphicsGetCurrentContext());
    
        }
        //--------------
        CGContextStrokePath(context);
        [super drawRect:rect];
    
        [curImage release];
    
    
    }
    
    0 讨论(0)
  • 2021-01-22 18:11

    Set the shadow in your graphics context to have a zero size offset, a blur of around 6-10 (change according to taste) and the same colour as your stroke colour. This will give all subsequent drawing a glow effect. The command is

    CGContextSetShadowWithColor()
    

    Documented here.

    0 讨论(0)
提交回复
热议问题