Create a nine patch image with code
<p>I am trying to create nine patch images programmatically. I have tried <a href="http://stackoverflow.com/questions/5079868/create-a-ninepatch-ninepatchdrawable-in-runtime/14061128#14061128">Griffey's</a> approach but can't seem to get it to work. There is very little information about how to use the class. I believe I am importing the bitmap incorrectly. If anyone knows how to get this to work or knows a better way, I'd greatly appreciate your help.</p>

<p>My code: </p>

<pre><code>// Dynamically create the 9patch image and apply it to a LinearLayout
LinearLayout llcode = (LinearLayout) findViewById(R.id.llcode);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.white_button);
Drawable np = NinePatchBitmapFactory.createNinePathWithCapInsets(getResources(), bitmap, 15, 15, 16, 16, null);

llcode.setBackgroundDrawable(np);

// The following code using the actual 9patch image: white_button_np.9.png
LinearLayout llxml = (LinearLayout) findViewById(R.id.llxml);
llxml.setBackgroundDrawable(getResources().getDrawable(R.drawable.white_button_np));
</code></pre>

<p>This screenshot shows the programmatic method on top and the typical 9patch method using the android tool on bottom.</p>

<p><img src="http://i.stack.imgur.com/6fx9i.png" alt="enter image description here"></p>

<p>The original image before it's converted to a 9patch.</p>

<p><img src="http://i.stack.imgur.com/pSUAR.png" alt="enter image description here"></p>
