swift
let image = UIImage.init(named: "1024-01")
/// t图片转data
let data = UIImagePNGRepresentation(image!)
// data 转string 注意是base64EncodedStringWithOptions 这个方法不能使用 [NSString.init(data: <#T##NSData#>, encoding: <#T##UInt#>)] 必须是这个编码
let str = data?.base64EncodedStringWithOptions(.Encoding64CharacterLineLength)
// string转data
let data1 = NSData(base64EncodedString:str!,options: .IgnoreUnknownCharacters)
// data 转 图片
let image2 = UIImage.init(data: data1!)
print(image2)
oc
UIImage *image = [UIImage imageNamed:@"640"];
NSData *data = UIImagePNGRepresentation(image);
NSString *str = [data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
NSLog(@"%@",str);
NSData *data1 = [[NSData alloc] initWithBase64EncodedString:str options:NSDataBase64DecodingIgnoreUnknownCharacters];
UIImage *image1 = [[UIImage alloc] initWithData:data1];
NSLog(@"%@",image1);
网友评论