首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CG中的纹理线

CG中的纹理线
EN

Stack Overflow用户
提问于 2014-04-05 11:58:27
回答 1查看 574关注 0票数 1

我正在为iOS开发一个绘图应用程序。在这个应用程序中,我需要绘制纹理线。为此,我使用的是这种方法.But 纹理是如此小,而不是形状。

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

这是我更新的代码-

代码语言:javascript
复制
        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 -

代码语言:javascript
复制
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了解甚少。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-05 16:28:52

但是纹理太小了而不是形状。

这是因为你只把图像画一次到路径的边框中。

你所做的就像把图像打印在一个小方格的真正有弹性的织物上,然后把它延伸到路径的大小。

使用一个大小为图像大小的矩形会将它放回“形状”,但它仍然很小,因为图像很小。而且,如果你只画了一次这样的大小,它就不会覆盖大部分路径的整个区域。

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22880587

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档