Skip to content

Instantly share code, notes, and snippets.

@oksep
Last active October 8, 2015 01:58
Show Gist options
  • Select an option

  • Save oksep/ec238da7a587b84aef5f to your computer and use it in GitHub Desktop.

Select an option

Save oksep/ec238da7a587b84aef5f to your computer and use it in GitHub Desktop.
Decode a stream to ninePatchDrawable
/**
* input must be create by /bin/crunk
*/
public static Drawable getNinePatchDrawable(Context context, InputStream input) {
Bitmap ninePathBmp = null;
ninePathBmp = BitmapFactory.decodeStream(input);
if (ninePathBmp == null) {
return null;
}
byte[] chunk = ninePathBmp.getNinePatchChunk();
boolean result = NinePatch.isNinePatchChunk(chunk);
if (result) {
return new NinePatchDrawable(context.getResources(), ninePathBmp, chunk, new Rect(), null);
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment