我试过这个
+ (NSString *)base64StringFromImage:(UIImage *)image {
NSData *data = UIImagePNGRepresentation(image);
NSString *base64Str = [data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
// base64Str = (__bridge NSString *) CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)base64Str, NULL, CFSTR(":/?#[]@!$&’()*+,;="), kCFStringEncodingUTF8);
return base64Str;
}
但是这个返回值base64Str无法转换回在线base642image工具webstation上的图像
答案 0 :(得分:2)
只需使用以下代码: -
NSData *imageData = UIImagePNGRepresentation(myImageView.image);
NSString * base64String = [imageData base64EncodedStringWithOptions:0];