#pragma mark 保存操作
UIGraphicsBeginImageContextWithOptions(_drawView.bounds.size, YES, 0);
CGContextRef context=UIGraphicsGetCurrentContext();
[_drawView.layer renderInContext:context];
_imgView.image=UIGraphicsGetImageFromCurrentImageContext();
//-------------------------------------画图----------------------------------------------------------------------------------
CGContextRef context=UIGraphicsGetCurrentContext();
//设置线的颜色
[_lineColor setStroke];
//设置线的宽度
CGContextSetLineWidth(context, _lineWith);
NSMutableArray *array=(NSMutableArray*)obj;
//第一个坐标
CGContextMoveToPoint(context, [[obj objectAtIndex:0] CGPointValue].x, [[obj objectAtIndex:0] CGPointValue].y);
CGPoint point=[array[i] CGPointValue];
CGContextAddLineToPoint(context, point.x, point.y);
CGContextStrokePath(context);
本文介绍了如何在iOS应用中使用UIGraphicsBeginImageContextWithOptions开始绘图,并将UIView的内容渲染到图片上下文中,最终获取并展示所绘制的图片。此外,还详细展示了如何通过CGContext进行线条的绘制,包括设置线条颜色、宽度以及绘制路径。
1053

被折叠的 条评论
为什么被折叠?



