2

Hi I am working on an application where i have to draw something. When I draw with marker stroke it makes some edges, how i can avoid these edges? enter image description here

enter image description here

Code for marker stroke

- (void)drawRect:(CGRect)rect
{
//    KidsPhotoBookAppDelegate *appDelegate = (KidsPhotoBookAppDelegate*)[[UIApplication sharedApplication]delegate];
//    brushPattern = (UIColor*)appDelegate.kidsSelectedColor;

    DBManager *dbMgr = [DBManager sharedManager];
    [dbMgr.c setStroke];
    for (UIBezierPath *_path in pathArray) 
        [_path strokeWithBlendMode:kCGBlendModeNormal alpha:1.0];  
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    KidsPhotoBookAppDelegate *appDelegate = (KidsPhotoBookAppDelegate*)[[UIApplication sharedApplication]delegate];

    myPath=[[UIBezierPath alloc]init];
    myPath.lineWidth = appDelegate.kidsBrushSize;
    myPath.lineCapStyle = kCGLineCapRound;
    brushPattern=appDelegate.kidsSelectedColor;
    UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
    [myPath moveToPoint:[mytouch locationInView:self]];
    [pathArray addObject:myPath];

    appDelegate.viewContainsDrawing = YES;
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
    [myPath addLineToPoint:[mytouch locationInView:self]];

    [self setNeedsDisplay];
}
Costique
  • 23,712
  • 4
  • 76
  • 79
Mashhadi
  • 3,004
  • 3
  • 46
  • 80
  • Duplicate? http://stackoverflow.com/questions/5076622/iphone-smooth-sketch-drawing-algorithm – basvk Mar 16 '12 at 14:22

3 Answers3

4

You should set line join to kCGLineJoinRound using CGContextSetLineJoin function. See the Quartz 2D Guide for more.

UPDATE

Since you are using UIBezierPath, you should try setting the lineJoinStyle of UIBezierPath to kCGLineJoinRound.

Tony
  • 1,581
  • 11
  • 24
1

How are you drawing those curves? If you're drawing a sequence of short straight line segments, that's the problem. You should be drawing these sorts of curves with a bezier path. If you're using a bezier path already, you may need to tweak the flatness property.

Caleb
  • 124,013
  • 19
  • 183
  • 272
0

I achieved this smoothness with the help of this code https://github.com/levinunnink/Smooth-Line-View

Mashhadi
  • 3,004
  • 3
  • 46
  • 80