保存图片信息通过NSData保存到本地文件中

//第一步:保存头像信息到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]; }

 

posted on 2015-05-22 11:19  奋进的闹钟  阅读(1540)  评论(0编辑  收藏  举报

导航