2012-04-12 37 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解決烏爾問題