把圖片轉(zhuǎn)為base64的字符串存到數(shù)據(jù)庫中或者plist文件中腰奋,然后用到的時候再取出來
//獲取沙盒路徑况芒,
NSString *path_sandox = NSHomeDirectory();
//創(chuàng)建一個存儲plist文件的路徑
NSString *newPath = [path_sandox stringByAppendingPathComponent:@"/Documents/pic.plist"];
NSMutableArray *arr = [[NSMutableArray alloc] init];
//把圖片轉(zhuǎn)換為Base64的字符串
NSString *image64 = [self encodeToBase64String:image];
[arr addObject:image64];
//寫入plist文件
if ([arr writeToFile:newPath atomically:YES]) {
NSLog(@"寫入成功");
};
這樣就存起來的试躏,然后用到的時候再利用存儲的字符串轉(zhuǎn)化為圖片。
NSData *_decodedImageData = [[NSData alloc] initWithBase64Encoding:image64];
UIImage *_decodedImage = [UIImage imageWithData:_decodedImageData];
//UIImage圖片轉(zhuǎn)成Base64字符串:
UIImage?*originImage?=?[UIImage?imageNamed:@"originImage.png"];
NSData?*data?=?UIImageJPEGRepresentation(originImage,?1.0f);
NSString?*encodedImageStr?=?[data?base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
//Base64字符串轉(zhuǎn)UIImage圖片:
NSData?*decodedImageData?=?[[NSData?alloc]?
initWithBase64EncodedString:encodedImageStr?options:NSDataBase64DecodingIgnoreUnknownCharacters];
UIImage?*decodedImage?=?[UIImage?imageWithData:decodedImageData];?