2012-04-12 69 views
5

我想永久保存绘制线并加载从项目资源保存的绘制线......!如何保存并加载绘制线iphone SDK

现在我得到的X和Y的位置触摸移动event.i想要保存项目中的本地资源的x和y位置,但我不是在ios的经验不知道...!

并加载从项目本地资源保存文件中保存的x和y位置。

我要救下图线是这样的:

enter image description here

请任何一个可以帮助我不胜感激...!

谢谢......!

回答

2

如果你想存储x和y的位置,你可以存储一个数组,然后用writeToFile将它保存到磁盘。这将以plist格式将数据写入磁盘。

NSMutableArray *points = ... 
[points writeToFile:someFileInTheBundle atomically:YES]; 

您还可以将图形存储为图像并将其写入磁盘。这一类我写的应该在这方面帮助通过给您的绘制代码的图像:https://github.com/kgn/BBlock/blob/master/UIImage%2BBBlock.m

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(); 
    } 
} 

将defenatly解决乌尔问题