Created
February 14, 2016 02:50
-
-
Save ZionPi/4d3910f4889945c02474 to your computer and use it in GitHub Desktop.
Set NinePatchDrawable as background using Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Bitmap bitmap = loadBitmapAsset("my_nine_patch_image.9.png", this); | |
ByteArrayOutputStream bos = new ByteArrayOutputStream(); | |
bitmap.compress(CompressFormat.PNG, 0 /* ignored for PNG */, bos); | |
byte[] bitmapdata = bos.toByteArray(); | |
ByteArrayInputStream bs = new ByteArrayInputStream(bitmapdata); | |
BitmapFactory.Options options = new BitmapFactory.Options(); | |
options.inSampleSize = 2; | |
Bitmap preview_bitmap = BitmapFactory.decodeStream(bs, null, options); | |
NinePatchDrawable drawable = NinePatchBitmapFactory | |
.createNinePatchDrawable(getResources(), preview_bitmap);//bitmap will be fine. | |
mTarget.setBackgroundDrawable(drawable); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment