我想永久保存绘图线并加载从项目资源中保存的绘图线...!
现在我在触摸移动事件中获得 x 和 y 位置。我想将 x 和 y 位置保存在项目的本地资源中,但我不知道 ios 的经验......!
并从项目本地资源保存文件中加载保存的 x 和 y 位置..!
我想像这样在下面保存绘图线:
请任何人帮助我非常感谢......!
谢谢...!
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if(!mouseSwiped) {
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear);
UIGraphicsBeginImageContext(ivBack.frame.size);
[drawImage.image drawInRect:CGRectMake(0,0, self.ivBack.frame.size.width,self.ivBack.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), line);
CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), [pickColor CGColor]);
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
CGContextFlush(UIGraphicsGetCurrentContext());
NSData *dataImage=UIImagePNGRepresentation(UIGraphicsGetImageFromCurrentImageContext());
[dataImage writeToFile:[self SavedImage:(@"1.png")] atomically:YES];
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
}
这将肯定地解决你的问题
如果要存储 x 和 y 位置,可以存储一个数组,然后使用writeToFile
. 这将以 plist 格式将数据写入磁盘。
NSMutableArray *points = ...
[points writeToFile:someFileInTheBundle atomically:YES];
您还可以将绘图存储为图像并将其写入磁盘。我写的这个类别应该通过为您的绘图代码提供图像来帮助解决这个问题:https ://github.com/kgn/BBlock/blob/master/UIImage%2BBBlock.m