Is it possible to make a pattern for a CGContext Path using a png
I want to make a path that has a png as it's pattern, or if you could or think it would be easier t开发者_如何学JAVAo make my own pattern, then tell me that also. I will be greatful to anyone who can put up some code. Thanks in advance
I don't know if I understand your question correctly. Are you trying to fill or stroke the path with the pattern? I guess the way to go is:
- Create the path you want to fill or stroke.
- Create a pattern with
CGPatternCreate()
. This function takes a lot of parameters, among them a pointer to a drawing callback function that will be called whenever the pattern is used. So you would place your code to draw the PNG image in this function. Create aCGImage
and useCGContextDrawImage()
to draw it into the graphics context provided by the callback function. - Call
CGContextSetFillColorSpace()
orCGContextSetStrokeColorSpace()
withCGColorSpaceCreatePattern()
to set a pattern color space (necessary for the next step). - Call
CGContextSetFillPattern()
orCGContextSetStrokePattern()
to tell Quartz to use your pattern for filling/stroking. - Call
CGContextDrawPath()
to draw the path.
Refer to the docs for more info on all these functions.
精彩评论