iOS 图片转成base64编码


 //UIImage图片转成Base64字符串:

    UIImage *originImage = [UIImage imageNamed:@"Cover.png"];

    NSData *data = UIImageJPEGRepresentation(originImage, 1.0f);

    NSString *encodedImageStr = [data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];

    

   NSLog(@"encodedImageStr==%@",encodedImageStr);

    //Base64字符串转UIImage图片:

    NSData *decodedImageData = [[NSData alloc]

                                initWithBase64EncodedString:encodedImageStr options:NSDataBase64DecodingIgnoreUnknownCharacters];

    UIImage *decodedImage = [UIImage imageWithData:decodedImageData];

    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(60, 100, 200, 400)];

    [imgView setImage:decodedImage];

    [self.view addSubview:imgView];

    NSLog(@"decodedImage==%@",decodedImageData);


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM