Using NinePatch (.9.png) for making scaled Bitmaps

此生再无相见时 提交于 2019-12-24 04:44:30

问题


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.


回答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);


来源:https://stackoverflow.com/questions/31777734/using-ninepatch-9-png-for-making-scaled-bitmaps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!