我想永久保存绘图线并加载从项目资源保存的绘图线......!
现在我在触摸移动事件上获得x和y位置。我想在项目的本地资源中保存x和y位置,但我不知道在ios中不知道......!
从项目本地资源保存文件中加载已保存的x和y位置..!
我想在下面保存绘图线:
请任何人帮助我,非常感谢......!
谢谢...!
答案 0 :(得分:3)
- (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();
}
}
肯定能解决你的问题
答案 1 :(得分:2)
如果要存储x和y位置,可以存储数组,然后使用writeToFile
将其保存到磁盘。这将以plist格式将数据写入磁盘。
NSMutableArray *points = ...
[points writeToFile:someFileInTheBundle atomically:YES];
您还可以将图形存储为图像并将其写入磁盘。我写的这个类别应该通过为您的绘图代码提供图像来帮助您:https://github.com/kgn/BBlock/blob/master/UIImage%2BBBlock.m