DivineDesert
DivineDesert

Reputation: 6954

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

Upvotes: 8

Views: 1248

Answers (3)

DivineDesert
DivineDesert

Reputation: 6954

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

Upvotes: 4

Rob Napier
Rob Napier

Reputation: 299475

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

Upvotes: 3

Abizern
Abizern

Reputation: 150665

It looks like you are drawing the path by using a series of circles.

The trouble is that you have set the shadow on the individual dots, and that's why you are getting the strange effects.

A possible solution - dont put a shadow on the dots, put on the path: duplicate the line that you have drawn, draw it in a different colour, offset it and put in under your actual line.

Alternatively, if you are using layers - have a look at shadow paths.

Upvotes: 0

Related Questions