UIImage&Base64流转换

  UIImage转成base64串

UIImage *image = self.pickImageView.image;

NSData *imageData = UIImageJPEGRepresentation(image, 0.3f);

//NSDataBase64EncodingEndLineWithLineFeed

这个枚举值是base64串不换行

NSString *imageBase64Str = [imageData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];

//    NSLog(@"%@",imageBase64Str);

if (imageBase64Str.length == 0) {

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"请选取图片" preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"好" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

}];

[alert addAction:okAction];

[self presentViewController:alert animated:NO completion:nil];

return;

}

  base64串转UIImage

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

UIImage *image = [UIImage imageWithData:imageData];

UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

imageView.frame = [UIScreen mainScreen].bounds;

[self.view addSubview:imageView];

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容