如何将数据转换为图像?

时间:2011-03-03 08:51:47

标签: iphone transform nsdata cfnetwork

我学习CFNetwork,socket,我差不多完成了。但是,我想使用UIImageView,所以 从URL接收数据,然后转换为UIImage,然后添加UIImageView

但我认为将数据转换为图像存在问题

我使用下面的代码...

void CFSockCallBack(CFSocketRef s, CFSocketCallBackType callbackType, CFDataRef address, const void *data, void *info){

     if (callbackType == kCFSocketDataCallBack) {
        UInt8 *d = (UInt8 *)CFDataGetBytePtr((CFDataRef)data);
        int len = CFDataGetLength((CFDataRef) data);

         NSData *nsdata = [NSData dataWithBytes:d length:len];

         imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 460.0)];
         UIImage *receiveImage = [UIImage imageWithData:nsdata];

imageView是实例delcared static。

你了解我的编码吗?那么 Plz帮帮我!!!

1 个答案:

答案 0 :(得分:0)

您是否将imageView的image属性设置为receiveImage?或者只是意外地遗漏了代码片段?你也得到某种错误信息或只是一个空白的UIImageView空间?

相关问题