iOS 1 NSData与UIImage之间的转换

//NSData转换为UIImage

//OC

NSData *imageData = [NSData dataWithContentsOfFile: imagePath];

UIImage *image = [UIImage imageWithData: imageData];

//UIImage转换为NSData

NSData *imageData = UIImagePNGRepresentation(image);

//UIImage转换为 JPEG 图片的 NSData 第二个参数代表压缩程度 取值范围 0 到 1

NSData *imageData = UIImageJPEGRepresentation(image, 0.4f);


//swift

var sourceData = NSData.init()

var image = UIImage.init(data: sourceData as Data)

var data = UIImagePNGRepresentation(image!)

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