title: How to Create UIImage from NSData and Avatar Data of XMPP?
body: <p>This question is related to Iphone SDK, NSData and UIImage.</p>
  
  <p>I am trying to create an image from the Avatar Data returned from the xmpp like the following:</p>
  
  <pre><code>&lt;presence from='yyy@184.73.164.51/spark' to='ken@184.73.164.51/424978324712783686768453' id='Oj02v-45'&gt;&lt;status&gt;Away due to idle.&lt;/status&gt;&lt;priority&gt;0&lt;/priority&gt;&lt;show&gt;away&lt;/show&gt;&lt;x xmlns='vcard-temp:x:update'&gt;&lt;photo&gt;a3f549fa9705e7ead2905de0b6a804227ecdd404&lt;/photo&gt;&lt;/x&gt;&lt;x xmlns='jabber:x:avatar'&gt;&lt;hash&gt;a3f549fa9705e7ead2905de0b6a804227ecdd404&lt;/hash&gt;&lt;/x&gt;&lt;/presence&gt;
  </code></pre>
  
  <p>So in this case, I assume that a3f549fa9705e7ead2905de0b6a804227ecdd404 is the photo data.
  So How can I transfer this into NSData?</p>
  
  <p>I think if I can get the NSData object, 
  I can easily create the UIImage, right?</p>
  
  <hr>
  
  <p>I think "a3f549fa9705e7ead2905de0b6a804227ecdd404" is the photo data
  this is my codes:</p>
  
  <pre><code>NSString* command = @"a3f549fa9705e7ead2905de0b6a804227ecdd404";
  command = [command stringByReplacingOccurrencesOfString:@" " withString:@""];
  NSMutableData *commandToSend= [[NSMutableData alloc] init];
  unsigned char whole_byte;
  char byte_chars[3] = {'\0','\0','\0'};
  int i;
  for (i=0; i &lt; [command length]/2; i++) {
      byte_chars[0] = [command characterAtIndex:i*2];
      byte_chars[1] = [command characterAtIndex:i*2+1];
      whole_byte = strtol(byte_chars, NULL, 16);
      [commandToSend appendBytes:&amp;whole_byte length:1]; 
  }
  
  UIImage *image = [UIImage imageWithData: commandToSend];
  </code></pre>
  
  <p>However,
  it doesn't work.
  Anyone knows what's wrong with it?</p>