图片 和 base64 互转
程序员文章站
2022-07-05 11:44:24
图片转base64 NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlStr]]; UIImage *img = [UIImage imageWithData:data]; NSString *img64 = [ ......
图片转base64
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlStr]];
UIImage *img = [UIImage imageWithData:data];
NSString *img64 = [self encodeToBase64String:img];
- (NSString *)encodeToBase64String:(UIImage *)image{
NSString * test = [UIImagePNGRepresentation(image) base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
return test;
}
base64转图片
NSData *data = [[NSData alloc]initWithBase64EncodedString:base64Str options:NSDataBase64DecodingIgnoreUnknownCharacters];
UIImage *img = [UIImage imageWithData:data];