我的项目是创建一个热图应用程序。为了访问以前记录的团队的热图,我需要知道如何使用图像上下文保存图纸。
- (void)drawRect
{
CGFloat dashes[2] = {25,25};
UIGraphicsBeginImageContext(self.field.frame.size);
[self.field.image drawInRect:CGRectMake(0, 0, self.field.frame.size.width, self.field.frame.size.height)];
if([_diagramselect selectedSegmentIndex]==3){
CGContextSetLineDash(UIGraphicsGetCurrentContext(), 0,dashes, 2);
}
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), startlocation.x-56, startlocation.y-92);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), endlocation.x-56, endlocation.y-92);
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapSquare);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), brush );
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red, green, blue, 1.0);
CGContextSetBlendMode(UIGraphicsGetCurrentContext(),kCGBlendModeNormal);
CGContextStrokePath(UIGraphicsGetCurrentContext());
self.field.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
如何保存我在场图像上绘制的内容以便以后访问?有可能吗?
答案 0 :(得分:0)
您可以从上下文创建图片参考。
CGImageRef imageMasked = CGBitmapContextCreateImage(context);
UIImage *finalImage = [UIImage imageWithCGImage:imageMasked];