开发者

Is it possible to make a pattern for a CGContext Path using a png

开发者 https://www.devze.com 2022-12-13 23:03 出处:网络
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

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:

  1. Create the path you want to fill or stroke.
  2. 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 a CGImage and use CGContextDrawImage() to draw it into the graphics context provided by the callback function.
  3. Call CGContextSetFillColorSpace() or CGContextSetStrokeColorSpace() with CGColorSpaceCreatePattern() to set a pattern color space (necessary for the next step).
  4. Call CGContextSetFillPattern() or CGContextSetStrokePattern() to tell Quartz to use your pattern for filling/stroking.
  5. Call CGContextDrawPath() to draw the path.

Refer to the docs for more info on all these functions.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号