CG中的纹理线

我正在为iOS的绘图应用程序工作。 在这个应用程序中,我需要绘制质感的线条。 对于这个我正在使用这种方法 。但是质地太小而不是形状。

我想知道我做错了什么,我该如何解决它。

这是我更新的代码 –

CGPoint mid1 = midPoint(previousPoint1, previousPoint2); CGPoint mid2 = midPoint(currentPoint, previousPoint1); [curImage drawAtPoint:CGPointMake(0, 0)]; CGContextRef context = UIGraphicsGetCurrentContext(); [self.layer renderInContext:context]; CGContextMoveToPoint(context, mid1.x, mid1.y); CGContextAddQuadCurveToPoint(context, previousPoint1.x, previousPoint1.y, mid2.x, mid2.y); CGContextSetLineCap(context, kCGLineCapRound); CGContextSetLineJoin(context, kCGLineJoinRound); CGContextSetLineWidth(context, self.lineWidth); //trans layer CGContextBeginTransparencyLayer(context, nil);// CGRect rect=CGContextGetPathBoundingBox (context);// CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);// //trans layer end CGContextSetShouldAntialias(context, YES); CGContextSetAllowsAntialiasing(context, YES); CGContextSetFlatness(context, 0.1f); CGContextSetAlpha(context, self.lineAlpha); CGContextStrokePath(context); //patter start CGContextSetFillColorSpace(context, CGColorSpaceCreatePattern(NULL)); static const CGPatternCallbacks callbacks = { 0, &lightDataArea, NULL }; CGPatternRef hello = CGPatternCreate(NULL, rect, CGAffineTransformIdentity, 0, 0, kCGPatternTilingConstantSpacing, YES, &callbacks); CGFloat alpha = 1; CGContextSetFillPattern(context, hello, &alpha); CGContextFillRect(context, rect); //pattern end //trans layer remaining CGContextSetBlendMode(context, kCGBlendModeSourceIn);// CGContextDrawImage(context, rect, [self image:[UIImage imageNamed:@"dddd.jpg"] withColor:[UIColor blueColor]].CGImage);// CGContextEndTransparencyLayer (context);// //trans layer end 

CGPatterCallback –

 void lightDataArea (void *info, CGContextRef context) { UIImage *image = [UIImage imageNamed:@"dddd.png"]; CGImageRef imageRef = [image CGImage]; CGContextDrawImage(context, CGRectMake(0, 0, 100, 100), imageRef); } 

这就是我所得到的

在这里输入图像说明

我的纹理图像

在这里输入图像说明

还是一样的结果。 请帮帮我。 我对CG很less了解。

但是质地太小而不是形状。

这是因为你正在绘制图像一次到path的边界矩形。

你所做的就像将图像打印到一个真正有弹性的小方形面料上,然后将其拉伸到path的大小。

使用尺寸与图像大小相同的矩形会使其恢复“形状”,但由于图像很小,所以它仍然很小。 而且,如果你只用这样的尺寸画一次,它就不能覆盖大部分path的整个区域。

您需要使用基于该图像的模式来填充矩形。 创build一个绘制图像的CGPattern ,然后将填充图案设置为该图案并填充path的边界矩形。