获得损坏的Base64编码图像

时间:2014-04-01 06:42:27

标签: ios iphone ios5

我已经尝试过google和stackoverflow,但无法得到满意的答案我是新手,并尝试编码图像发送/上传到服务器,然后在base64图像中解码相同的图像,并在我的collectionview的Cell的imageview中显示。

  1. 我已经成功编码了base64中的图像,我已经检查了在线base64格式化程序中的编码字符串,并在输出中获取了我的图像,因此我的编码工作正常。
  2. 2解码时出现以下错误.....

    <Error>: ImageIO: JPEG Unsupported marker type 0x6c 
    <Error>: ImageIO: JPEG Corrupt JPEG data: 1 extraneous bytes before marker 0x6c
    

    我使用以下代码解码图像

    NSString *imageURL  =  [imagename objectAtIndex:indexPath.row];
    
    NSData *imageData   =  [Base64 decode:imageURL];
    
    ImageView.image     =  [UIImage imageWithData:imageData];
    

    任何建议和建议将不胜感激....

1 个答案:

答案 0 :(得分:0)

试试这个......

NSString *imageString  =  [imagename objectAtIndex:indexPath.row];

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"data:image/png;base64,%@",imageString]];

NSData *imageData = [NSData dataWithContentsOfURL:url];

ImageView.image = [UIImage imageWithData:imageData];