title: How to get stream bytes and convert back to image - IOS
body: <p>How to get stream bytes and convert back to image, below is my code.
  But the images I get is blank. Why?
  Something wrong of the code?</p>
  
  <p>I get the bytes from my NSOutputStream and convert back to NSData, then convert the NSData to image.</p>
  
  <pre><code>(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 &gt; 0) {
  
                  NSData *pictureData = [NSData dataWithBytes:buffer length:len];
  
                  UIImage *imagess = [[UIImage alloc]initWithData:pictureData];
                  [imagesview setImage:imagess];
  
  
  
  
                                  }
  
          }
      }
      break;
  
  }
  </code></pre>
  
  <p>}</p>