UIImage的绘制图案不像图案,但在UIView中填充了UIImage

时间:2013-03-04 08:38:08

标签: iphone cgcontext cgcontextdrawimage

我的代码行:

UIColor *brushPattern=[[UIColor alloc]initWithPatternImage:[UIImage imageNamed:@"Frame-1@2x.png"]];
CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(),brushPattern.CGColor);
Image pattern

url

它不会像画笔图案那样绘制,而是填充UIView

中的图案

1 个答案:

答案 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();