title: Create a NinePatch/NinePatchDrawable in runtime
body: <p>I have a requirement on my Android application that parts on the graphics should be customizable, by retrieving new colors and images from the server side. Some of these images are nine-patch images.</p>
  
  <p>I can't find a way to create and display these nine-patch images (that have been retrieved over the network).</p>
  
  <p>The nine-patch images are retrieved and kept in the application as Bitmaps. In order to create a <a href="http://developer.android.com/reference/android/graphics/drawable/NinePatchDrawable.html" rel="nofollow noreferrer">NinePatchDrawable</a>, you either need the corresponding <a href="http://developer.android.com/reference/android/graphics/NinePatch.html" rel="nofollow noreferrer">NinePatch</a> or the chunk (<code>byte[]</code>) of the NinePatch. The NinePatch can NOT be loaded from the Resources, since the images doesn't exist in <code>/res/drawable/</code>. Furthermore, in order to create the NinePatch, you need the chunk of the NinePatch. So, it all drills down to the chunk.<br>
  The question is then, how do one format/generate the chunk from an existing Bitmap (containing the NinePatch information)?</p>
  
  <p>I've searched through the Android source code and the Web and I can't seem to find any examples of this. To make things worse, all decoding of a NinePatch resources seem to be done natively.</p>
  
  <p>Have anyone had any experiences with this kind of issue?</p>
  
  <p>I'm targeting API level 4, if that is of importance.</p>