码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-05-22 13:11:40      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

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

 

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

标签:

原文地址:http://www.cnblogs.com/allanliu/p/4521845.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!