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

2017-01-14  本文已影响123人  天才iOS程序员

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

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];

上一篇 下一篇

猜你喜欢

热点阅读