//第一步:保存头像信息到NSData中
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); self.documentsPath = [paths objectAtIndex:0]; NSString *imagePath = [NSString stringWithFormat:@"%@/%@.jpg", self.documentsPath, contacts.Photo]; UIImage *tempImage = [UIImage imageWithContentsOfFile:imagePath]; headOldImageData = [NSData dataWithData:UIImageJPEGRepresentation(tempImage, 1.0)]; [headOldImageData retain];
//第二步:修改后用writeToFile归档
NSString *imagePath = [NSString stringWithFormat:@"%@/%@.jpg", self.documentsPath, oldImageName]; if([fileManager fileExistsAtPath:imagePath]) { [headOldImageData writeToFile:[NSString stringWithFormat:@"%@/%@.jpg", self.documentsPath, oldImageName] atomically:YES]; }
时间: 2024-10-10 22:25:17