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

posted @ 2016-06-15 13:54  光光96  阅读(16403)  评论(0编辑  收藏  举报