title: NSData to byte array (or array of integers)
body: <p>I am working with a webservice which gives me an image as an array of integers. I have managed to convert this array into an <code>NSData</code> object and then into a <code>UIImage</code> using the code below.
  Now I am in doubt how I will convert an image into a similar array.</p>
  
  <p>The array looks like this:</p>
  
  <pre><code>[255,216,255,224,0,16,74,70,73,70,0,1,1,1,0,96,0,96,0,0,255,219,0,67,0,8,6,6,7,6,5,8,7,7,7,9,9,8,10,12,...]
  </code></pre>
  
  <p>This is the code I use to convert the above array to a <code>UIImage</code>.</p>
  
  <pre><code>+ (UIImage *)imageFromBytes:(NSArray *)bytes
  {
      unsigned char *buffer = (unsigned char *) malloc(bytes.count);
      int i = 0;
      for (NSDecimalNumber *num in bytes)
          buffer[i++] = num.intValue;
      NSData *data = [NSData dataWithBytes:buffer length:bytes.count];
      free(buffer);
  
      return [UIImage imageWithData:data];
  }
  </code></pre>
  
  <p>So, I need to convert a <code>UIImage</code> into an array of integers (a byte array).</p>
  
  <p>Can anybody point me in the right direction?</p>