1. 保存
- (void)saveImage:(UIImage*)image {
NSArray*paths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);NSString*filePath = [[paths objectAtIndex:0]stringByAppendingPathComponent:[NSStringstringWithFormat:@"demo.png"]];// 保存文件的名稱
BOOLresult =[UIImagePNGRepresentation(image)writeToFile:filePath? atomically:YES];// 保存成功會返回YES
if(result ==YES) {
??? NSLog(@"保存成功");
?}
}
2取出保存的圖片
- (void)getImage {
NSArray*paths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);NSString*filePath = [[paths objectAtIndex:0]stringByAppendingPathComponent:[NSStringstringWithFormat:@"demo.png"]];
// 保存文件的名稱
UIImage*img = [UIImageimageWithContentsOfFile:filePath];
NSLog(@"=== %@", img);
}