Note that there are some explanatory texts on larger screens.

plurals
  1. PODraw clean and smooth free hand drawing with CGContext (alpha + blend)
    primarykey
    data
    text
    <p>Following is my code for free hand drawing using CGContext. I want to use the color having alpha value 0.6 and the blend mode as <code>kCGBlendModeColor</code>. But while drawing, I get the following effect : the color is overlapping and becomes dark. I want non overlapping and smooth draw. </p> <pre><code> -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; lastTouch = [touch locationInView:self]; } -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint currentTouch = [touch locationInView:self]; CGFloat brushSize = 35; UIColor *color = [UIColor blueColor]; CGFloat red = 0.0, green = 0.0, blue = 0.0, alpha = 0.0; if ([color respondsToSelector:@selector(getRed:green:blue:alpha:)]) { [color getRed:&amp;red green:&amp;green blue:&amp;blue alpha:&amp;alpha]; } else { const CGFloat *components = CGColorGetComponents(color.CGColor); red = components[0]; green = components[1]; blue = components[2]; alpha = components[3]; } UIGraphicsBeginImageContext(self.frame.size); CGContextRef context = UIGraphicsGetCurrentContext(); [self.image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)]; CGContextSetLineCap(context, kCGLineCapRound); CGContextSetLineWidth(context, brushSize); CGContextSetRGBStrokeColor(context, red, green, blue, 0.6) ; CGContextSetBlendMode(context, kCGBlendModeColor); CGContextBeginPath(context); CGContextMoveToPoint(context, lastTouch.x, lastTouch.y); CGContextAddLineToPoint(context, currentTouch.x, currentTouch.y); CGContextStrokePath(context); self.image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); lastTouch = [touch locationInView:self]; } </code></pre> <p><img src="https://i.stack.imgur.com/qpzib.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload