How to render a tricky ass NinePatch?
<p>This is thebasic idea, but the image is ugly and pixelated. WHY???</p>

 <pre><code>
public class Main extends Activity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    ImageView iv = (ImageView) findViewById(R.id.iv);
    Bitmap bmap = BitmapFactory.decodeResource(getResources(), R.drawable.btn_default_normal);
    NinePatchDrawable npd = new NinePatchDrawable(bmap, bmap.getNinePatchChunk(), new Rect(0,0,512,512), "name");
    npd.mutate();
    npd.setBounds(new Rect(0,0,512,512));
    npd.invalidateSelf();
    Bitmap bp = Bitmap.createBitmap(512,512, Bitmap.Config.RGB_565);
    Canvas canvas = new Canvas(bp);
    npd.draw(canvas);
    FileOutputStream ofo=null;
    try {
      ofo = openFileOutput("image", MODE_WORLD_READABLE);
    } catch (IOException e) {
      e.printStackTrace();
    }
    bp.compress(Bitmap.CompressFormat.PNG, 100, ofo);
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.putExtra(Intent.EXTRA_STREAM, getFileStreamPath("image").toURI());
    intent.setType("image/png");
    //startActivity(intent);
    iv.setImageDrawable(new BitmapDrawable(bp));
  }
}
</code></pre>
