美文网首页
UIImage&Base64流转换

UIImage&Base64流转换

作者: eduzon | 来源:发表于2018-07-10 17:43 被阅读0次

      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];

    相关文章

      网友评论

          本文标题:UIImage&Base64流转换

          本文链接:https://www.haomeiwen.com/subject/emdqpftx.html