// 3.图片base64转换
// 先获取压缩图片
UIImage *compressionImage = [selforiginImage:_profileImageView.imagescaleToSize:CGSizeMake(120, 120)];
// 再转换图片
NSData *data = UIImageJPEGRepresentation(compressionImage, 1.0f);
NSString *encodedImageStr = [data base64Encoding];
// 4. 参数发给服务器
[selfupdateUserWithDictionary:@{@"token": token,
@"logo": encodedImageStr
}];
// 上传图片的压缩, 体积变小
-(UIImage*)originImage:(UIImage *)image scaleToSize:(CGSize)size
{
UIGraphicsBeginImageContext(size);
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return scaledImage;
}
// 文字base64 demo
[xmlString appendFormat:@"<contentText>%@</contentText>",[[contentText dataUsingEncoding:NSUTF8StringEncoding] base64Encoding]];