Reputation: 493
I am trying to create an application where I can write. I have progressed in that by using CGContextRef. I have written a following code.
previousPoint2 = previousPoint1;
previousPoint1 = [touch previousLocationInView:m_secondaryDrawingImgeView];
currentPoint = [touch locationInView:m_secondaryDrawingImgeView];
// calculate mid point
CGPoint mid1 = [self midPoint:previousPoint1 :previousPoint2];
CGPoint mid2 =[self midPoint:currentPoint :previousPoint1];
UIGraphicsBeginImageContext(m_secondaryDrawingImgeView.frame.size);
[m_secondaryDrawingImgeView.image drawInRect:
CGRectMake(0, 0, m_secondaryDrawingImgeView.frame.size.width,
m_secondaryDrawingImgeView.frame.size.height)];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextMoveToPoint(context, mid1.x, mid1.y);
// Use QuadCurve is the key
CGContextAddQuadCurveToPoint(context,
previousPoint1.x, previousPoint1.y, mid2.x, mid2.y);
// NSMutableArray *arr = [NSMutableArray arrayWithObjects:mid1, nil]
// NSLog(@"%@",color);
CGContextSetStrokeColorWithColor(context, color.CGColor);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineWidth(context,m_width);
CGContextStrokePath(context);
m_secondaryDrawingImgeView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
When I set opacity to my color it shows dots in line, which I want to remove.
Is it the right path i am going on? Is there any way i can remove those dots?
Attaching images for more clarity. What is happening after writing this code is image-1 and what i want is image-2
Upvotes: 4
Views: 3836
Reputation: 493
Finally I cracked it. you have to set blend mode for this following is the code
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeCopy);
Upvotes: 7