标签:
将图片存储到本地
NSArray *dirArray = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); NSString *path = [dirArray firstObject]; path = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"IDCARD%zd",_selectIndex]]; NSData *imageData = UIImageJPEGRepresentation(image, 1.0); [imageData writeToFile:path atomically:YES];
图片的存到本地之后的读取
NSArray *dirArray = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); NSString *path = [dirArray firstObject]; path = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"IDCARD%zd",i]]; if([[NSFileManager defaultManager] fileExistsAtPath:path]){ NSData *picData = [NSData dataWithContentsOfFile:path]; view.idCardImageView.image = [UIImage imageWithData:picData]; }
将存储到本地的图片删除
NSArray *dirArray = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); NSString *path = [dirArray firstObject]; path = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"IDCARD%zd",i]]; if([[NSFileManager defaultManager] fileExistsAtPath:path])//如果存在临时文件的配置文件 { [[NSFileManager defaultManager] removeItemAtPath:path error:nil]; }
标签:
原文地址:http://www.cnblogs.com/carlos-mm/p/5797925.html