【问题标题】:Drawing pattern with UIImage not like pattern but it is filled UIImage in UIView用 UIImage 绘制图案不像图案,但它在 UIView 中填充了 UIImage
【发布时间】:2013-03-04 08:38:08
【问题描述】:

我的代码行:

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

url

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

【问题讨论】:

  • 希望下面的代码会有所帮助

标签: iphone cgcontext cgcontextdrawimage


【解决方案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();

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-03
  • 1970-01-01
  • 1970-01-01
  • 2013-07-27
  • 2015-04-17
相关资源
最近更新 更多