Swift
// 获取图片
let uploadImage = UIImage(named: "imageName");
// 读取UIImage的JPEG格式的数据 后面参数:压缩比例
let uploadData = UIImageJPEGRepresentation(uploadImage!, 0.2);
// 进行gzip压缩
let gzipData = uploadData.gzippedData;
// 进行base64
let encodedImageStr = gzipData()!.base64EncodedStringWithOptions(.Encoding64CharacterLineLength);
OC
UIImage *uploadImage = [UIImage imageNamed:@"imageName"];
// 读取UIImage的JPEG格式的数据 后面参数:压缩比例
NSData *uploadData = UIImageJPEGRepresentation(uploadImage, 0.2f);
// 进行gzip压缩
NSData *gzipData = [uploadData gzippedData];
关于UIImageJPEGRepresentation和UIImagePNGRepresentation区别请见这里
http://www.jianshu.com/p/8745f435e6c3
原址点此GZIP,感谢作者: Nick Lockwood
学习途径:钟师傅