2

Possible Duplicate:
convert bitmap into ninepatch to use as background

I am trying to change a specific color to a different color on a nine-patch. So far the only way I can think to do it is - create a bitmap from a ninepatch in resources, copy the bitmap to make it mutable and give it a rgb-8888 configuration, put it through the method that runs through changing the color, then create a new nine-patch from the bitmap. But when I try to get the byte[] chunk data for the new nine-patch from the bitmap copy "after the color change" it starts the activity blinks black and returns to the parent activity. And if I get the byte[] chunk data from the original bitmap "before the color change" It works but wherever it stretches it puts the original color. Here is my code so far.

  Bitmap backMap = BitmapFactory.decodeResource(getResources(),R.drawable.outerbackground);
  byte[] chunk = backMap.getNinePatchChunk();

  backMap = backMap.copy( Bitmap.Config.ARGB_8888, true);


  backMap = getChangedColor(backMap, Color.rgb(212, 212, 212), Color.rgb(255, 50, 0));


  NinePatchDrawable np_drawable = new NinePatchDrawable(getResources(), backMap, chunk, new Rect(), null);
  np_drawable.setBounds(0, 0, backMap.getWidth(), backMap.getHeight());

I think the reason that it stretches with the old color is the byte[] chunk data I am getting from the original bitmap"before the color change". I think I either need to get the chunk data from the bitmap copy"after the color change" or figure out how to change the data in the byte[] chunk to represent the color change. If anyone has a clue on how to make this work or a better way to do it, I would appreciate it so much. I have been stuck on this for a week.

Community
  • 1
  • 1
Bob
  • 142
  • 2
  • 13

0 Answers0