首页 > 其他 > 详细

2016-03-09 保存图片

时间:2016-03-09 10:39:15      阅读:128      评论:0      收藏:0      [点我收藏+]

下面介绍我最后使用的一个办法。

先把图片直接存储到沙盒中。 然后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];

2016-03-09 保存图片

原文:http://www.cnblogs.com/gzz2016/p/5256937.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!