如何在程序中存储图像(不在照片库中)

时间:2011-12-01 18:00:03

标签: iphone xcode

我用以下代码存储图像但发生错误,我应该如何存储图像(不是像这种方法那样在程序中的照片库中)?

NSMutableArray *array=[[NSMutableArray alloc]init];
[array addObject:[UIImage imageNamed:@"a"]];
[array addObject:[UIImage imageNamed:@"b"]];
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [path objectAtIndex:0];
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:@"SaveCartoons"];
NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
[dict setObject:array forKey:@"1"];
[NSKeyedArchiver archiveRootObject:dict toFile:fullPath];

1 个答案:

答案 0 :(得分:1)

那里的代码可能不会保存。

首先,UIImage不是易于存档的东西。

查看answer to this question并将您的UIImage转换为NSData,然后将其添加到您的可变数组中。