2

I need to draw a Bitmap for my new Android Application. Since my content view is set to a Game-Panel class I've created. I want to display images through Bitmap. Just because its more convenient, and easier to do then anything else. From what I've gathered from researching, Nine Patch images (.9.png) are used in android to scale more properly then regular Drawable images. It also says "This can be used for scaling properly in backgrounds. For example a regular button background...". If Nine Patch images are made to scale better. Can You use a Nine Patch for making a Bitmap in a specific width and height because it would scale more properly? For example

Bitmap b = createBitmap(BitmapFactory.decodeResource(NinePatchImage), x, y, width, height);

Is this possible? Should I do it a different way? Should I create a bitmap first and then just scale the bitmap? Is this even necessary? Please help.

5
  • I think you need to elaborate on why you need a Bitmap. I doubt that you actually need one. Aug 2, 2015 at 23:57
  • To display an image. Aug 3, 2015 at 0:07
  • Yeah, and why couldn't you use a Drawable? Aug 3, 2015 at 0:22
  • Because I'm not using the standard XML file for my content view. So I need to display images proggrmatically. Aug 3, 2015 at 1:17
  • Are you aware of the draw method? Aug 3, 2015 at 1:21

1 Answer 1

1
Bitmap bitmap = Bitmap.createBitmap(canvasWidth, canvasHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
NinePatchDrawable drawable = (NinePatchDrawable) getResources().getDrawable(R.drawable.myDrawable);
drawable.setBounds(new Rect(x, y, width, height));
drawable.draw(canvas);
2
  • What is the difference between drawing a NinePatchDrawable and a Bitmap using a Nine Patch resource. Aug 3, 2015 at 1:30
  • I guess the obvious difference is that one works and one doesn't? Aug 3, 2015 at 2:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.