NinePatchDrawable from Drawable.createFromPath or FileInputStream
- by Tim H
I cannot get a nine patch drawable to work (i.e. it is stretching the nine patch image) when loading from either Drawable.createFromPath or from a number of other methods using an InputStream.
Loading the same nine patch works fine when loading from when resources. Here's the methods I am trying:
Button b = (Button) findViewById(R.id.Button01);
Drawable d = null;
//From Resources (WORKS!)
d = getResources().getDrawable(R.drawable.test);
//From Raw Resources (Doesn't Work)
InputStream is = getResources().openRawResource(R.raw.test);
d = Drawable.createFromStream(is, null);
//From Assets (Doesn't Work)
try {
InputStream is = getResources().getAssets().open("test.9.png");
d = Drawable.createFromStream(is, null);
} catch (Exception e) {e.printStackTrace();}
//From FileInputStream (Doesn't Work)
try {
FileInputStream is = openFileInput("test.9.png");
d = Drawable.createFromStream(is, null);
} catch (Exception e) {e.printStackTrace();}
//From File path (Doesn't Work)
d = Drawable.createFromPath(getFilesDir() + "/test.9.png");
if (d != null) b.setBackgroundDrawable(d);