我正在爲iOS的繪圖應用程序工作。在這個應用程序中,我需要繪製質感的線條。對於這個我使用this method。但紋理是如此之小,不在形狀。CG中的紋理線條
我想知道我做錯了什麼,我該如何解決它。
這是我更新的代碼 -
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很少了解。
在您顯示的代碼中,您在將圖像與筆畫混合之前忘記了描邊路徑。 –