I am trying to create nine patch images programmatically. I have tried Griffey's 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.
My 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));
This screenshot shows the programmatic method on top and the typical 9patch method using the android tool on bottom.
The original image before it's converted to a 9patch.