下面介绍我最后使用的一个办法。
先把图片直接存储到沙盒中。 然后plist文件中记录图片的路径。然后要使用图片的时候通过访问plist文件获取图片路径来调用。
下面是使用示例:
一。图片存储到沙盒中
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"pic_%d.png", myI]]; // 保存文件的名称
[UIImagePNGRepresentation(myImage) writeToFile: filePath atomically:YES];
二。在plist中保存路径
NSMutableDictionary *info = [[NSMutableDictionary alloc]init];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"pic_%d.png", conut_]]; // 保存文件的名称
[info setObject:filePath forKey:@"img"];
[specialArr addObject:info];
三。使用图片
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"pic_%d.png", (int)current]]; // 保存文件的名称
UIImage *img = [UIImage imageWithContentsOfFile:filePath];