Emboss Effect in Core Graphics

I'm here again with two Questions, both interconnected

  • I want to draw embossed lines with the main graphics. Can someone suggest me how to give the inner shadows a line drawn on touch events?
  • Even for drawing outer shadows. The shadow overlay overlaps between them. and the line drawn in colors other than black looks like a worm .. Can someone help me? The following image illustrates what I would like to explain for Question 2: enter image description here Shadows are not even created. They darken at some points.

I am adding code that I use to draw strings.

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; } 
+8
objective-c iphone ios4 core-graphics quartz-graphics
source share
3 answers

I have found my solution. The problem was very stupid ... I clicked the path at each iteration that created the problem. Now I can draw even with alpha less than 1 ...

 CGContextStrokePath(context); 

This line goes beyond the loop. And now everything is working fine.

+4
source share

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

+3
source share

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

The problem is that you set the shadow on individual points and why you get strange effects.

A possible solution is do not put shadows on the dots, put on the path: duplicate the line that you drew, draw it with a different color, shift it and put it in your current line.

Alternatively, if you use layers, look at the shadow paths.

0
source share

All Articles