2012-06-21 186 views
2

我正在创建一个贺卡应用程序。我有一些现有的模板,我也可以通过添加剪贴画,文字等创建新的贺卡。我已经保存图像作为一个uiimage对象。我卡住了以保存这些图像以供将来使用。请帮助。ios应用程序中保存图像

+1

参考http://stackoverflow.com/questions/7620165/iphonehow-can-i-store-uiimage-using-nsuserdefaults –

回答

2

要保存一个UIImage到文件执行以下操作

NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/img.jpg"]; 

//Save 
NSData* imageData = UIImageJPEGRepresentation(img, 1.0); 
[imageData writeToFile:path atomically:YES]; 

//Load 
NSData* imageData = [NSData dataWithContentsOfFile:path]; 
UIImage *image = [UIImage imageWithData:imageData]; 
0

看看这个链接。 How to save picture to iPhone photo library?

您还可以通过将图像转换为数据并将数据保存到文件来将图像保存在iPhone文件系统中。

NSData *data = UIImagePNGRepresentation(yourImage); 
[data writeToFile:(NSString *)path atomically:(BOOL)useAuxiliaryFile] 
相关问题