Android: how to create a 9patch image from an inputstream?
<p>I am using the below code to instantiate a 9patch image and set it as the background of a button.  The following image shows the non-ideal result. </p>

<pre><code>InputStream = MyClass.class.getResourceAsStream("/images/btn_default_normal.9.png");
Drawable d = NinePatchDrawable.createFromStream(in, null);
button.setBackgroundDrawable(d);
</code></pre>

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

<p>Tried the below code as well, which seems to result in an ANR caused by native android code.  It's not really clear what happens, but the application exists without warning, the log says something about an ANR, and I see the following  stacktrace quite a bit in the log. </p>

<pre><code>InputStream = MyClass.class.getResourceAsStream("/images/btn_default_normal.9.png");
Bitmap bitmap = BitmapFactory.decodeStream(in);
byte[] chunk = bitmap.getNinePatchChunk();
NinePatchDrawable drawable = new NinePatchDrawable(bitmap, chunk, new Rect(), null);
button.setBackgroundDrawable(drawable);



 at android.graphics.NinePatch.validateNinePathChunk(Native Method)
at android.graphics.NinePatch.&lt;init&gt;
at android.graphics.drawable.NinePatchDrawable.&lt;init&gt;
</code></pre>
