美文网首页
IOS沙盒图片保存读取 ---by talent.L

IOS沙盒图片保存读取 ---by talent.L

作者: 天才iOS程序员 | 来源:发表于2017-01-14 20:29 被阅读123次

//这是从内存里拿到图片后重新保存到沙盒  你拿你想要的代码就行

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);

NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"a.jpg"]];  // 保存文件的名称

BOOL result = [UIImagePNGRepresentation(image1.image)writeToFile: filePath    atomically:YES]; // 保存成功会返回YES

if (result) {

NSLog(@"内存图片保存成功");

}

}];

//这是从沙盒读取读取图片

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);

NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"a.jpg"]];

image1.image = [[UIImage alloc] initWithContentsOfFile:filePath];

相关文章

网友评论

      本文标题:IOS沙盒图片保存读取 ---by talent.L

      本文链接:https://www.haomeiwen.com/subject/rqtybttx.html