我的代码行:
UIColor *brushPattern=[[UIColor alloc]initWithPatternImage:[UIImage imageNamed:@"Frame-1@2x.png"]];
CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(),brushPattern.CGColor);
Image pattern
它不像画笔图案那样绘制,而是填充图案UIView
我的代码行:
UIColor *brushPattern=[[UIColor alloc]initWithPatternImage:[UIImage imageNamed:@"Frame-1@2x.png"]];
CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(),brushPattern.CGColor);
Image pattern
它不像画笔图案那样绘制,而是填充图案UIView
我已经使用了以下代码
在 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();