Objective C: Using UIImage for Stroking

I am trying to apply a texture for my brush but i’m really having a hard time figuring how it is done.

Here’s the image of my output.

  • 'ld: file not found' after changing product name in Xcode
  • How to avoid keyboard hide & show when focus changes from UITextField and UIWebView?
  • How Do I Route Audio to Speaker without using AudioSessionSetProperty?
  • Kill Command for a jailbroken iPhone
  • How can i start my UITableView section with number 0 when i have multiple sections?
  • Return to root view in IOS
  • I used an UIImage that just follows the touch on the screen but when i swipe it faster the result is on the right side “W”, and on the left side that’s the result when i swipe it slow.

    enter image description here

    i tried using the CGContextMoveToPoint and CGContextAddLineToPoint i don’t know how apply the texture.

    Is it possible to use UIImage for the stroke texture?

    Here’s my code

        UIImage * brushImageTexture = [UIImage imageNamed:@"brushImage.png"]; 
        [brushImagetexture drawAtPoint:CGPointMake(touchCurrentPosition.x, touchVurrentPosition.y) blendMode:blendMode alpha:1.0f];
    

    Solutions Collect From Internet About “Objective C: Using UIImage for Stroking”

    You need to manually draw the image at each point along the line from the previous point to the current point.

    CGPoint vector = CGPointMake(currentPosition.x - lastPosition.x, currentPosition.y - lastPosition.y);
    CGFloat distance = hypotf(vector.x, vector.y);
    vector.x /= distance;
    vector.y /= distance;
    for (CGFloat i = 0; i < distance; i += 1.0f) {
        CGPoint p = CGPointMake(lastPosition.x + i * vector.x, lastPosition.y + i * vector.y);
        [brushImageTexture drawAtPoint:p blendMode:blendMode alpha:1.0f];
    }