base64解码和编码范例(iPhone和Mac通用)

文章详细介绍了如何通过WebService从服务器端获取Base64编码的图片,并解析为UIImage对象的过程。包括解析流程、所需关键步骤及实际应用示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

以下内容来自网络,链接 http://www.cocoachina.com/bbs/read.php?tid-8858.html

首先下载 base64.zip;

如果你想从webService服务器端,获取图片,又如果服务端返回的图片是基于base64编码的,那么你可以往下看:

首先你要先会解析webService服务器返回的各种类型数据,这个不在本文讨论范围,可以自己去看相关资料。

比如说先用NSString类型变量接收服务端返回的base64字节流:

 

NSString*stringValue=/*the UTF8 string parsed from xml data*/
Byte inputData[[stringValuelengthOfBytesUsingEncoding:NSUTF8StringEncoding]];//prepare a Byte[]
[[stringValuedataUsingEncoding:NSUTF8StringEncoding]getBytes:inputData];//get the pointer of the data
size_t inputDataSize =(size_t)[stringValuelength];
size_t outputDataSize = EstimateBas64DecodedDataSize(inputDataSize);//calculate the decoded data size
Byte outputData[outputDataSize];//prepare a Byte[] for the decoded data
Base64DecodeData(inputData, inputDataSize, outputData, &outputDataSize);//decode the data
NSData*theData =[[NSDataalloc]initWithBytes:outputData length:outputDataSize];//create a NSData object from the decoded data
  然后你就可以用这个theData初始化UIImage了;   

图像资源的可以用这个网址:里面的图像返回是用base64编码:http://webservice.webxml.com.cn/WebServices/ValidateCodeWebService.asmx?op=cnValidateByte

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值