Ios - Drawing a brush from fingers

I want to draw my iPad app as shown in the following image

enter image description here in my application, I placed the image and, moving my finger (touch), I repeat the images, but my image looks like this.

enter image description here

Below is my code for drawing an image

CGBlendMode blendMode = kCGBlendModeColorDodge; UIGraphicsBeginImageContext(drawImage.frame.size); [drawImage.image drawInRect:CGRectMake(0, 0, drawImage.frame.size.width, drawImage.frame.size.height)]; CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); //// NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"Watercolor-edge-45x45.png" ofType:nil]; UIImage * textureColor;// = [UIImage imageWithContentsOfFile:imagePath]; float angle = hypot(deltaX, deltaY); angle *= rand() % 180;//(M_PI / 180); CGPoint vector = CGPointMake(currentPoint.x - lastPoint.x, currentPoint.y - lastPoint.y); CGFloat distance = hypotf(vector.x, vector.y); vector.x /= distance; vector.y /= distance; for (CGFloat i = 0; i < distance; i += 1.0f) { textureColor = [UIImage imageWithCGImage:[self CGImageRotatedByAngle:image angle:angle * -1]]; CGPoint p = CGPointMake(lastPoint.x + i * vector.x, lastPoint.y + i * vector.y); [textureColor drawAtPoint:p blendMode:blendMode alpha:0.1f]; } CGContextBeginPath(UIGraphicsGetCurrentContext()); CGContextStrokePath(UIGraphicsGetCurrentContext()); UIImage *newimage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); 

How to get an image like in the first image

In fact, I have an image and fill the selected color on the image and start drawing here I have an image enter image description here

+4
source share

Source: https://habr.com/ru/post/1433769/


All Articles