iOS开发中 UIImage可能经常需要转为NSData 上传 传递等等
有两个比较常用的方法
UIImageJPEGRepresentation
UIImagePNGRepresentation
第一个方法有两个参数
UIImageJPEGRepresentation(UIImage * __nonnull image, CGFloat compressionQuality);
我们直接上代码
吧两种方式做一个比较
我们创建一个项目,调用系统的相册或者照相机 取一张图片
先用第一种方式转换一个清晰度较高的图片(此处我们贴出重要代码,其他代码我们会上传到qq群空间,请见文章底部)
UIImage *image;
image=[info valueForKey:UIImagePickerControllerOriginalImage];
imageData = UIImageJPEGRepresentation(image,1);
float length = [imageData length]/1024;
NSLog(@&