如何获取流字节并转换回图像,下面是我的代码。但是我得到的图像是空白的。为什么?代码有问题吗?
我从我的 NSOutputStream 中获取字节并转换回 NSData,然后将 NSData 转换为图像。
(void)stream:(NSStream *)theStream handleEvent:(NSStreamEvent)streamEvent {
switch (streamEvent) {
case NSStreamEventOpenCompleted:
NSLog(@"Stream opened");
break;
case NSStreamEventHasBytesAvailable:
if (theStream == inputStream) {
uint8_t buffer[5000];
int len;
while ([inputStream hasBytesAvailable]) {
len = [inputStream read:buffer maxLength:sizeof(buffer)];
NSLog(@"len=%d", len);
if (len > 0) {
NSData *pictureData = [NSData dataWithBytes:buffer length:len];
UIImage *imagess = [[UIImage alloc]initWithData:pictureData];
[imagesview setImage:imagess];
}
}
}
break;
}
}