我需要为我的新Android应用程序绘制一个Bitmap。由于我的内容视图设置为我创建的Game-Panel类。我想通过Bitmap显示图像。只是因为它更方便,更容易做到其他任何事情。 根据我从研究中收集的信息,在Android中使用Nine Patch图像(.9.png)来比常规的Drawable图像更加正确。它还说"这可以用于在背景中正确缩放。例如,常规按钮背景......"。如果使九个补丁图像更好地扩展。您是否可以使用Nine Patch制作特定宽度和高度的位图,因为它可以更正确地缩放?例如
option=""
while (option !='help' and option!='start'):
option=raw_input()
if option == 'help':
print "content of the help file"
elif option == 'start':
run(host='localhost', port=8080)
else:
print "not a valid option, try again"
这可能吗?我应该采用不同的方式吗?我应该首先创建一个位图然后只是缩放位图吗?这甚至是必要的吗?请帮忙。
答案 0 :(得分: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);