0

我想转换这个字节数据以从中获取图像。我使用了这种 base64Encoding 方法,但这似乎没有用。

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

        NSString *base64StringEncoder = @"data:image/png;base64,";
    base64StringEncoder = [base64StringEncoder stringByAppendingString:[[parserDataContentArray objectAtIndex:indexPath.row] exhibitorByteImageObjectClass]];
    NSURL *profilePicURL = [NSURL URLWithString:base64StringEncoder];
    NSData *profilePicimageData = [NSData dataWithContentsOfURL:profilePicURL];

    if (profilePicimageData.length!=0) {
        cell.exhibitorImage.image = [UIImage imageWithData:profilePicimageData];
    }

        return cell;

}

其中 parserDataContentArray 是保存已解析数据的可变数组。ExistorByteImageObjectClass 是我在检查特定标签存在后设置节点的 NSString 属性。

XML 看起来像

<PRODUCTION_B_IMAGE>
iVBORw0KGgoAAAANSUhEUgAAAKAAAACPCAYAAAB9NdDOAAAKQ2lDQ1BJQ0MgUHJvZmlsZQAASA2dlndUU1kTwO97L73QEkKREnoNTUoAkRJ6kV5FJSQBQgkYErBXRAVXFBVpig==
</PRODUCTION_B_IMAGE>
4

1 回答 1

3

请下载:NSData+Base64 文件

dataWithContentsOfURL 实际上并不从 URL 中获取数据,而是从位于 URL 处的资源中获取数据。这是最容易使用(解码和编码)base64 字符串的包装器之一。

[parserDataContentArray objectAtIndex:indexPath.row]我相信你有你的 NSString 和 base64 数据。所以试试这个:

NSData *tempData = [NSData dataFromBase64String:[parserDataContentArray objectAtIndex:indexPath.row]];
if (tempData.length!=0) {
    cell.exhibitorImage.image = [UIImage tempData];
}
于 2013-07-17T08:48:32.733 回答