//这是从内存里拿到图片后重新保存到沙盒 你拿你想要的代码就行
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];
网友评论