NSData与UIImage之间的转换

NSData转换为UIImage:

//从本地拿数据     
NSString *imagePath = [[NSBundle mainBundle] pathForResource:fileName ofType:type];
//fileName为图片文件名,type为图片类型 ,假如有一张oneImage.png的图片
//NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"oneImage" ofType:@"png"];
NSData *imageData = [NSData dataWithContentsOfFile:imagePath];
//从网络拿数据     urlStr为统一资源定位符(即网站地址)
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlStr]];
UIImage *image = [UIImage imageWithData:imageData];

UIImage转换为NSData

NSData *imageData = UIImagePNGRepresentation(image);

你可能感兴趣的:(NSData与UIImage之间的转换)