Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emboss effect in Core Graphics

I am again here with two Question, both inter-related

  1. I want to draw embossed lines with core graphics. Can any one suggest me how to give inner shadows to line drawn on touch events?
  2. Even for drawing outer shadows. Shadow drawn overlaps in between. and line drawn with colors other than black is like worm.. Can any one help me? Following image illustrates what I mean to explain for Question 2: enter image description here Shadows creates are not even. They darken at some points

I am adding the code that I am using to draw lines..

    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);

        CGContextSetLineCap(context, kCGLineCapRound);
        CGContextSetStrokeColorWithColor(context,[color CGColor]);              
        CGContextSetLineWidth(context, linewidth);              
        CGContextStrokePath(context);
        i+=2;
    }
like image 756
DivineDesert Avatar asked Feb 27 '12 12:02

DivineDesert


2 Answers

I found my solution.. Problem was very silly... I was stoking path on every iteration which was creating the issue.. Now I can draw even with alpha less then 1..

CGContextStrokePath(context);

This line goes outside for loop.. And all is working fine now :)

like image 182
DivineDesert Avatar answered Nov 12 '22 21:11

DivineDesert


For your overlapping shadows, you want a transparency layer to composite them first. See Transparency Layers in the Quartz 2D Programming Guide.

like image 31
Rob Napier Avatar answered Nov 12 '22 19:11

Rob Napier