CAShapeLayer to change the width of different Brushes

188 Views Asked by At

I am having different Texture Brushes I am having the image of those texture of each pixel of the stroke I want to assign the texture to the CGPath and change the width . I need to assign the texture image and change the width to the slider response.

1

There are 1 best solutions below

1
On

You achieve this in the following order:

  • Use CGLayerCreateWithContext to create a CGLayer, during this stage, the slider value is obtained and used as the CGSize in the initializer.
  • Use CGLayerGetContext to get the context of the CGLayer created, then you render your brush texture with the context, for example, CGContextDrawImage.
  • Use the completed CGLayer as a texture and draw it on screen with CGContextDrawLayerAtPoint, since you got your CGPath, you need to manually calculate the density of your drawing, and generate an array of CGPoint to be used as a parameter in the drawing function.

You may reference the Quartz 2D Programming Guide by Apple.