问题
I have a problem I've been stuck on for a few days. I am trying to convert a nine patch image into a bitmap array, and change a specific color to a different one. I am having trouble converting the bitmap back to a nine patch, so I can use it as a background for a layout. I have tried using this code to create the bitmap then convert it back to a nine-patch drawable, but it just starts the activity and blinks black then goes back to the parent activity. If I comment out the creation and initialization of the nine-patch the activity starts just fine.
Bitmap backMap = BitmapFactory.decodeResource(getResources(),R.drawable.outerbackground);
backMap = backMap.copy(Bitmap.Config.ARGB_8888, true);
backMap = getChangedColor(backMap, Color.rgb(212, 212, 212), Color.rgb(55, 50, 255));
byte[] chunk = backMap.getNinePatchChunk();
NinePatchDrawable np_drawable = new NinePatchDrawable(getResources(), backMap, chunk, new Rect(), null);
np_drawable.setBounds(0, 0, backMap.getWidth(), backMap.getHeight());
I usually don't ask for help on such a thing, but I have went through all the documentation I could find on nine-patch images and bitmaps and still can't figure it out.
Long question short, I need to know how to convert a bitmap to a nine-patch image for use as a background. Thanks a million in advance. you'll get the other million after your done.
O and I am targeting version 16 with the minimum of 8.
来源:https://stackoverflow.com/questions/13983775/convert-bitmap-into-ninepatch-to-use-as-background