我的代码行:
UIColor *brushPattern=[[UIColor alloc]initWithPatternImage:[UIImage imageNamed:@"Frame-1@2x.png"]];
CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(),brushPattern.CGColor);
Image pattern
它不会像画笔图案那样绘制,而是填充UIView
答案 0 :(得分:1)
我使用了以下代码来实现相同的
在ViewDidLoad或者你要去哪里开始分配
patternColor = [UIColor colorWithPatternImage:image]
这将解决您的内存问题,以下代码将帮助您
UIGraphicsBeginImageContextWithOptions(view.frame.size, NO, [[UIScreen mainScreen] scale]);
CGContextRef context = UIGraphicsGetCurrentContext();
[view.image drawInRect:CGRectMake(0, 0, view.frame.size.width, view.frame.size.height)];
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineWidth(context, 10);
CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), patternColor.CGColor);
CGContextSetBlendMode(context, kCGBlendModeNormal);
CGContextBeginPath(context);
CGContextMoveToPoint(context, lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(context, currentPoint.x, currentPoint.y);
CGContextStrokePath(context);
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();