//图片转成data数据
+ (NSData *)dataFromImage:(UIImage *)image {
NSData *data;
if (UIImagePNGRepresentation(image) == nil) {
data = UIImageJPEGRepresentation(image, 1);
} else {
data = UIImagePNGRepresentation(image); //图片质量高,大小很大
}
return data;
}
NSData *headData = [self dataFromImage:headImage];//headImage为图片
NSString *baseEncodingHead = [headData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
params = @{@"file" : baseEncodingHead, @"fileName" : @".png"};
用afn上传图片到服务器就行了