iOS 图片转base64 base64转图片

//1.图片转64base字符串

- (NSString *)imageToString:(UIImage *)image {

NSData *imagedata = UIImagePNGRepresentation(image);

NSString *image64 = [imagedata base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];

return image64;

}

//2. 64base字符串转图片

- (UIImage *)stringToImage:(NSString *)str {

NSData * imageData =[[NSData alloc] initWithBase64EncodedString:str options:NSDataBase64DecodingIgnoreUnknownCharacters];

UIImage *photo = [UIImage imageWithData:imageData ];

return photo;

}

 

posted on 2022-06-06 08:58  高彰  阅读(761)  评论(0编辑  收藏  举报

导航