1-#pragma mark - 保存圖片到沙盒中一個方法atom
- (void)saveImage:(UIImage *)currentImage withName:(NSString *)imageName {
// 高保真壓縮圖片,但圖片質量基本保持不變,第二個參數即圖片質量參數
NSData *imageData = UIImageJPEGRepresentation(currentImage, 0.5);
// 獲取沙盒目錄
NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents" ] stringByAppendingString:imageName];
// 將圖片寫入文件
[imageData writeToFile:fullPath atomically:NO];
}圖片
2-從沙盒中讀取剛纔保存的圖片地址string
// 從沙盒中取出圖片
NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingString:@"aaa"];
NSLog(@"%@",NSHomeDirectory());
self.imageView.image = [[UIImage alloc]initWithContentsOfFile:fullPath];it
注意⚠️:上述中aaa地址名字是本身命名的, (aaa==imageName)方便在Documents中查看io