title: Hex String to Image
body: <p>I have a hex string which looks like: </p>
  
  <pre><code>String hexImage ="0xFFD8FFE000104A46494600010200006400640000FFEC00114475636B79000100040000003C..."
  </code></pre>
  
  <p>Which I need to convert to an image using Java. I've tried converting to a byte array first with  org.apache.commons.codec.binary.Hex class. FileOutputStream later dumps this to a file. </p>
  
  <pre><code>char[] charArr= hexImage.toCharArray();
  byte[] byteArray = Hex.decodeHex(charArr);
  </code></pre>
  
  <p>however the parser in the Hex class chokes, with an Decoder exception :  Odd number of characters. No matter what method I use to convert to a byte array, it fails. The fileformat is definitely a JPEG.</p>
  
  <p>I've tried removing <strike>this</strike> 0xFF from the string, but the image is corrupt at this point. 0xFF I assume is a the culprit - anyone any ideas on what do I need to do to correct this?</p>